I need to save a value of type Object?
in the Provider state in Flutter, but I can't check if it's empty or not.
Object? _session = {};
Object? get session => _session;
set session(Object? newValue) {
_session = newValue;
notifyListeners();
}
Then in widget
AppStateContent content = Provider.of<AppStateContent>(context);
The content.session.isEmpty
returns The getter 'isEmpty' isn't defined for the type 'Object'.
The content.session != {}
doesn't return the EmptyScreen()
widget when the session object isn't modified.
content.session != {}
? const CurrentScreen()
: const EmptyScreen(),
CodePudding user response:
Try leaving it in the null.
Object? _session;
Object? get session => _session;
set session(Object? newValue) {
_session = newValue;
notifyListeners();
}
content.session != null
? const CurrentScreen()
: const EmptyScreen(),