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'


Solution 1: iDecode

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');
}