Replace
onPressed: Navigator.push(...)
with
onPressed: () => Navigator.push(...)
If you need to use await
keyword, you can do
onPressed: () async {
await Navigator.push(...);
await anyOtherMethod();
}
@Petro Navigator.push
returns a Future
and onPressed
accepts void
, which is why you can't directly assign Navigator.push
to onPressed
, however when you do onPressed: () =>
You're simply executing Navigator.push(...)
inside the callback provided by onPressed
. Hope that explained!
LateError (LateInitializationError: Field '_database@181296932' has not been initialized.)