jeudi 24 septembre 2020

Failed assertion: boolean expression must not be null on if-else statement Flutter Riverpod

I am using riverpod (Very new to it) to make my state management solution... Here is the riverpod provider variable


    final userAuthProvider = StateProvider<Map<String, bool>>(
        (_) => {'signedIn': false, 'loaded': true, 'signInWasDissmised': false});

And here is how I use it


    Widget getRightPage(BuildContext context) {
        final appState = context.read(userAuthProvider).state;
        print(appState['loaded']);
        if (appState['loaded']) {
          if (!appState['signedIn'] && !appState['singInWasDissmised']) {
            return SignIn();
          } else if (!appState['signedIn'] && appState['singInWasDissmised']) {
            return Home();
          }
          return Home();
        }
        print(appState);
        return Splash();
      }

When I run the code I get this

Failed assertion: boolean expression must not be null

Which is totally weird as when I print the Map it works fine (Without any null values) see screenshot below

Does anyone know what's wrong? What am I missing? Why do I get this error when I don't have any null values?

Thanks

enter image description here

Aucun commentaire:

Enregistrer un commentaire