flutter constructor example

Example 1: constructor in dart

//Creating object.
void main(){
  SelfDrivingCar myLamb = SelfDrivingCar('Floride');
  myLamb.drive();
 
}

//Initializing class Car.
class Car {
  int numberofwheels = 4;
  
  void drive() {
    print('this is a car');
  }
}

//using Inheritance 
class SelfDrivingCar extends Car {
  String destination='k';
  
  SelfDrivingCar(String userDestination){ //constructor
    destination = userDestination;
  }
  @override    //polymorphism.
  void drive() {
    super.drive();  // accessing parent's methods.
    
    print('sterring wheel to $destination');
    
  }
}

Example 2: constructoers in flutter

Customer(this.name, this.age, this.location);

Customer.withoutLocation(this.name, this.age);

Customer.empty() {
  name = "";gd
  location = "";
}
cfgdfgdfgdfggdfgdfdfgdfgdggdfgdfgdf