Skip to content

Instantly share code, notes, and snippets.

@arpit
Last active July 22, 2019 15:10
Show Gist options
  • Save arpit/17352b8e0553f3acf3e91bc57af7b479 to your computer and use it in GitHub Desktop.
Save arpit/17352b8e0553f3acf3e91bc57af7b479 to your computer and use it in GitHub Desktop.
Dart snippets

Null check operator ??

String name = person.name ?? "Adam"

Optional ?.

pages[0]?.contributors[0]?.authorDetails?.basicInfo?.firstName ?? 

Assign if null ??=

String name ??= "arpit"

Cascade

Create an object and set its variables and return the main object that was created

Point p = Point()
          ..x = 4
          ..y = 5;

Add asserts to constructors

CropRectPainter(this.rect, {this.scaleSize}) : assert(rect != null);

Add @required to named arguments

CropRectPainter(this.rect, {@required String scaleSize});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment