Is there a way to initialize a field of a class with a function (where multiple steps would be required)?
Example: instead of:
class User {
final String uid;
final String fireBaseDisplayName;
String shortenedName;
User({
this.uid,
this.fireBaseDisplayName,
}) : shortenedName =
fireBaseDisplayName.substring(0, fireBaseDisplayName.indexOf(' '));
}
would this be possible:
User({
this.uid,
this.fireBaseDisplayName,
}) : shortenedName =
shortenName(this.fireBaseDisplayName));
}
shortenName (fireBaseDisplayName) {
return fireBaseDisplayName.substring(0, fireBaseDisplayName.indexOf(' ');
};
Related What is the difference between constructor and initializer list in Dart?