userName
userName

Reputation: 945

How to check for null on onWillPop values?

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?

Upvotes: 0

Views: 56

Answers (1)

AJ-
AJ-

Reputation: 1783

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;
    },

Upvotes: 1

Related Questions