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');
}
![iDecode](https://i.stack.imgur.com/8Jlh3.png?s=256&g=1)
Author by
iDecode
When developers want to hide something from you, they put it in docs.
Updated on December 30, 2022Comments
-
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'