'How to write an expression into a method?

How can I write the expression into a separate method for optimization:

final listOfKeys= [_firstTabNavKey, _secondTabNavKey, _thirdTabNavKey]

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


Solution 1:[1]

Like this ?

Future<bool> _popBack() async {
   return !(await listOfKeys[tabController.index].currentState?.maybePop() ?? false);
}

onWillPop: _popBack,

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1