Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i initialize super class variables in dart language?

Tags:

dart

Simply i have to classes child and parent class
i am new in dart language all i need to assign super class properties from child class

this is super class structure

class Trip{
  final int id;
  final String title;
  final double price;
  Trip({this.id,this.title,this.price});
}

and this is child class

class FullTrip extends Trip{
  final String data;
  FullTrip({this.data}) : super(id:id,title:title,price:price);
}

sure this not working at all
the question is : how can i initialize instance from FullTrip and pass variable for FullTrip and Trip(super class)
thanks in advance

like image 690
Roufail Avatar asked Jan 12 '19 16:01

Roufail


People also ask

How do you access the super class variable in darts?

Syntax: // To access parent class variables super. variable_name; // To access parent class method super. method_name();


1 Answers

You need to repeat the parameters in the subclass.

class FullTrip extends Trip{
  final String data;
  FullTrip({this.data, int id, String title, double price}) : super(id:id,title:title,price:price);
}

There are discussions about reducing such boilerplate for constructors, but nothing is decided yet as far as I know.

like image 103
Günter Zöchbauer Avatar answered Sep 23 '22 23:09

Günter Zöchbauer