Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

dart set final variable in constructor

// You cannot mutate final variables in a constructor body, 
// instead you must use a special syntax.
// Also note if you have a super() call, it must be called last.
class Point {
  final num x;
  final num y;
  final num distanceFromOrigin;

  // Special syntax
  Point(this.x, this.y) :
    distanceFromOrigin = sqrt(pow(x, 2) + pow(y, 2));
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dart #set #final #variable #constructor
ADD COMMENT
Topic
Name
5+5 =