A value of type 'Future<bool?>' can't be returned from the method because it has a return type of 'Future<bool>

1,153

Navigator.push can't return a non-nullable type because in your /bar route, you could probably do the following without passing any value in the result parameter.

Navigator.pop(context);

You should change your signature from Future<bool> to Future<bool?>:

Future<bool?> foo(BuildContext context) {
  return Navigator.pushNamed<bool>(context, '/bar');
}
Share:
1,153
iDecode
Author by

iDecode

When developers want to hide something from you, they put it in docs.

Updated on December 30, 2022

Comments

  • iDecode
    iDecode over 1 year
    Future<bool> foo(BuildContext context) {
      return Navigator.pushNamed<bool>(context, '/bar'); // Error
    }
    

    Error:

    A value of type 'Future<bool?>' can't be returned from the function 'foo' because it has a return type of 'Future'