Dart cheatsheet

Published 3 months ago: October 25, 2020


Dart cheatsheet.

This cheatsheet is a small collection of handy snippets for quick reference in tricky situations. Feel free to suggest edits, propose additions, complain about something, disagree with content or such and the like. Every feedback is a welcome one.

Useful libraries

Standard library

Print

print('Hello, World!');

Basic function

void main() { print('Hello, World!'); }

Run Dart script from the command line

dart /path/to/script.dart

Directory

var myDir = new Directory('/home/user/dir/');

List files in a directory

var myDir = new Directory('/home/user/dir/');

void checkDir(theDir) {
  theDir.exists().then((isThere) {
    isThere ? print('exists') : print('non-existent');
    listDir(theDir);
  });
}

void listDir(theDir) {
    theDir.list(recursive: true, followLinks: false)
    .listen((FileSystemEntity entity) {
        print(entity.path);
    });
}

checkDir(myDir);

Handy resources from around the web


Christoffer Lybekk

Developer under development

Explore more articles with similar tags

DartFlutterCheatsheet

Article stats


81words

19sentences

19paragraphs

1 minread time