Skip to content

Instantly share code, notes, and snippets.

Last active July 22, 2019 15:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Dart snippets

Null check operator ??

String name = ?? "Adam"

Optional ?.

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

Assign if null ??=

String name ??= "arpit"


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