Closed
Description
I have an optional selectedFlight
property in a class like this:
class ModelFlight with ChangeNotifier {
//+++
static ModelFlight get to => di<ModelFlight>();
//+++
Flight? _selectedFlight;
Flight? get selectedFlight => _selectedFlight;
set selectedFlight(Flight? value) {
_selectedFlight = value;
notifyListeners();
}
}
...but it crashes when I set up the property value watcher in a widget:
Widget build(BuildContext context) {
watchPropertyValue((ModelFlight model) => model.selectedFlight); //<-- !! Exception !!
}
_TypeError (Null check operator used on a null value)
How can I watch a nullable property that won't be set until later?
Metadata
Assignees
Labels
No labels