Answers for "dart class fields final"

0

dart class fields final

class Point {
  final num x;
  final num y;
  final num distanceFromOrigin;

  Point._(this.x, this.y, this.distanceFromOrigin);

  factory Point(num x, num y) {
    num distance = distanceFromOrigin = sqrt(pow(x, 2) + pow(y, 2));
    return new Point._(x, y, distance);
  }
}
Posted by: Guest on January-07-2021
0

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));
}
Posted by: Guest on May-28-2020

Code answers related to "Dart"

Browse Popular Code Answers by Language