I have two constructors in new_activity_config.dart.
NewActivityConfig(this.activityType, {Key key, this.activity}) : super(key: key);
NewActivityConfig.fromNewActivityConfig(this.activity, {Key key, this.activityType}) : super(key: key);
One takes in an activityType: this.name, this.image
The other takes in an activity: this.name, this.image, this.status, this.scheduledStart, this.mapped, this.description, this.statistics, this.completionDate, this.duration
When navigating from the Pick Activity screen, it will call the NewActivityConfig() constructor - because it is showing an empty Config page for the user to input values
When selecting an already created activity, it will call the NewActivityConfig.fromNewActivityConfig(), passing in variables that had been previously input to fill the fields.
In my TextField hintText, I would like to display the user's input description if the description variable exists. However, if the first constructor is called (not passing in any user's previous values) and getDescription() cannot be called because it hasn't been passed in - and receive the error: The method getDescription() was called on null.
How can I check if this exists without running into null errors?
final description = TextField(
decoration: InputDecoration(
hintText:(widget.activity.getDescription() != null ? widget.activity.getDescription() : 'Enter an activity description'),
)
);
Aucun commentaire:
Enregistrer un commentaire