flutter class default value code example

Example 1: flutter default fvalue

int findVolume(int length, int breadth, {int height = 12}) {
  return length*breadth*height;
}

Example 2: fluter class constructor

class Customer {
  String name;
  int age;
  String location;

  // constructor
  Customer(String name, int age, String location) {
    this.name = name;
    this.age = age;
    this.location = location;
  }
}

Example 3: flutter constructor default value

class Customer {
  String name;
  int age;
  String location;

  Customer(this.name, [this.age, this.location = "US"]);

  
  String toString() {
    return "Customer [name=${this.name},age=${this.age},location=${this.location}]";
  }
}

Tags:

Dart Example