-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to dismiss the sheet manually if there is navigation inside? #49
Comments
For solving this you need to understand how BuildContext works. Navigator.of(context) will get you the closest Navigator to the context reference. As you have added a Navigator, it will return that Navigator and not the one you used to push the modal button sheet. For getting the Navigator you used for pushing the modal, you have different options. The preferred is to use a key to reference the navigator, you have a great example this: Otherwise, you can pass a context reference from before the inner new Navigator showBarModalBottomSheet(
expand: true,
context: context,
backgroundColor: Colors.transparent,
builder: (context, scrollController) {
return Navigator(
onGenerateRoute: (_) => MaterialPageRoute(
builder: (context2) => Builder(
builder: (context3) => CupertinoPageScaffold(
...
children: <Widget>[
GestureDetector(
child: Container(
...
onTap: () {
// context2 or context3 will return the Navigator inside the modal
Navigator.pop(context);
},
),
}
),
); |
As this is not an issue related to the library, I am going to close the issue, feel free to ask more if you don't manage to solve it. |
Thanks a lot for your timely help, @jamesblasco. Lifesaver! |
Understand that normally we use
Navigator.of(context).pop();
to dismiss the modal sheet.However in my case, there is navigation inside the modal sheet. So, using
Navigator.of(context).pop();
will only return to the previous page of the sheet.I tried to google and use methods such as
Navigator.of(context).popUntil((route) => route.isFirst);
but still fail.Anyone can shed some light on this? Many thanks.
The text was updated successfully, but these errors were encountered: