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?
CodePudding user response:
Try this:
onWillPop: () async {
await Navigator.pushReplacementNamed(
context,
'/category',
arguments: CategoryArgument(
args.catSlug,
args.catName,
),
);
return true;
}
CodePudding user response:
with this line you can go back:
Navigator.pop(context);