AlienDecoy
AlienDecoy

Reputation: 109

Check Object? for empty

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(),

Upvotes: 1

Views: 4407

Answers (1)

Sulaymon Ne&#39;matov
Sulaymon Ne&#39;matov

Reputation: 448

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(),

Upvotes: 1

Related Questions