Reputation: 7128
I am trying to get back button of phone to go to specific page using WillPopScope
but it does not work (won't respond) at all.
Code
@override
Widget build(BuildContext context) {
final args = ModalRoute.of(context)!.settings.arguments as ArticleArgument;
return WillPopScope(
onWillPop: () async {
Navigator.pushReplacementNamed(
context,
'/category',
arguments: CategoryArgument(
args.catSlug,
args.catName,
),
);
return true;
},
child: Scaffold(...)
);
}
Any idea?
Upvotes: 0
Views: 628
Reputation: 12673
Try this:
onWillPop: () async {
await Navigator.pushReplacementNamed(
context,
'/category',
arguments: CategoryArgument(
args.catSlug,
args.catName,
),
);
return true;
}
Upvotes: 2