Reputation: 153
I'm making pattern shape lock function. I'm stuck in the problem that when the pattern is successes it has to go HomePage() that I made in another file. so I implemented return HomePage() in if block below. but It occurs error that
The return type 'HomePage' isn't a 'Future', as required by the closure's context.
How Can I work arrange this?
if (pattern != null) ...[
SizedBox(height: 16),
MaterialButton(
color: Colors.green,
child:
Text("Check Pattern", style: TextStyle(color: Colors.white)),
onPressed: () async {
final result = await Navigator.pushNamed(
context,
"/check_pattern",
arguments: pattern,
);
if (result == true) {
context.replaceSnackbar(
content: Text(
"it's correct",
style: TextStyle(color: Colors.green),
),
);
return HomePage();
}
},
Upvotes: 0
Views: 317
Reputation: 63569
onPressed
method is void,void Function();
doesnt return widget. If you like to navigate new routine based on condition, you can wrap with Navigator.of(context).push
replace return HomePage();
with
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => HomePage(),
));
Upvotes: 1