If you want a value to be the same across different instances of the same class, use the static
keyword:
class Person {
static var defaultName = 'Kshitij';
String name;
Person([this.name]){
name ??= defaultName; // if name is null, use default name.
}
}
Now you can change the default name to Agarwal by writing:
Person.defaultName = 'Agarwal';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.