Skip to content

Instantly share code, notes, and snippets.

@arpit
Last active Jul 22, 2019
Embed
What would you like to do?
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