I'm working on a FLutter application and found a strange issue.
I have got this widget:
@override
Widget build(BuildContext context) {
var route = ModalRoute.of(context)!.settings.name;
return IconButton(
icon: const Icon(
UniconsLine.previous,
shadows: [
BoxShadow(
blurRadius: 15.0,
color: Colors.black,
),
BoxShadow(
blurRadius: 15.0,
color: mainBgColor,
)
],
size: 40,
),
onPressed: () {
print(route);
Navigator.pop(context);
},
);
}
What I'm trying to do is pop the content and go back to the previous page. Somehow, all I got is a blank page. The route is "/" here. On the other pages, the route is just null. When I'm using the Android navigation button it routes to the previous page.
What is the solution for this?
CodePudding user response:
Try this
Navigator.of(context).maybePop();
or
Navigator.of(context, rootNavigator: true).pop(context);
If both not works try this
SystemNavigator.pop();