1

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?

1
  • how do you navigate to this widget? do you pushNamedAndRemoveUntil ? maybe that caused the route to be null. because it will remove all the previous routes Commented Aug 12, 2022 at 7:39

1 Answer 1

3

Try this

 Navigator.of(context).maybePop();

or

Navigator.of(context, rootNavigator: true).pop(context);

If both not works try this

SystemNavigator.pop();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.