Home > Blockchain >  How to check for null on onWillPop values?
How to check for null on onWillPop values?

Time:05-06

I need to do a null check:

onWillPop: () async {
        return !await listOfKeys[tabController!.index].currentState!.maybePop();
      },
Instead of "!" should I use "??". But I can't write it down. How can I do that?

CodePudding user response:

when you use the null safety operator ´??´ you should provide a fallback value:

    onWillPop: () async {
      return tabController != null
      ? !(await listOfKeys[tabController?.index].currentState?.maybePop() ?? false)
      : false;
    },
  • Related