I have implemented a filter feature in my app, which opens up a modalBottomSheet with some filtering options when a user clicks on a particular button.
I want to get data from my database based on the filters, right when the user clicks/swipes away from the modalBottomSheet.
How do I detect that they've done this?
Is there a better way to do this?
showModalBottomSheet(
context: context,
builder: (context){
return Text("example");
}).then((value) => {
//database things
});
You can use like this. You can detect bottomsheet is closed with this way.
I use showModalBottomSheet to render a bottom sheet with buttons (StatefulWidgetWithButtons). Once a button is pressed the state of the sheet changes and it gets re-rendered with different content.
I would like that depending on a certain state the sheet becomes not dismissable. I can achieve this using
showModalBottomSheet(
isDismissable: false
builder: (context) => StatefulWidgetWithButtons()
)
however what I want to achieve is that depending on a certain button pressed within StatefulWidgetWithButtons the isDismissable property changes to true (or false).
I don't know how to achieve this since I know I can change the StatefulWidgetWithButtons but that won't rebuild the bottom sheet.
I also don't want to close and show again the bottom sheet but change its dismissable behaviour while it is rendered
I was able to get this behaviour by wrapping the non-dismissible layout variant of the bottom sheet in a GestureDetector with vertical drag handler like so:
GestureDetector(
onVerticalDragUpdate: (_) {},
child: ...
This prevents the default modal bottom sheet drag handlers from taking action
If you want to learn more about this solution and how it works you can read about it here: https://stackoverflow.com/a/71622120/11676468
It definitely seems more like a workaround/hack but it looks like the only alternative is to implement a completely custom showModalBottomSheet from scratch
Image understands you the purpose better
https://i.stack.imgur.com/Z45YH.jpg
I tried everything but failed!
Navigating
Navigating to a new Page is easy
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
"SecoundRoute" is the Widget you will open in a new Window.
More information about this here.
Swipe gesture
This is a bit more complicated. There is a widget called "Dismissible" but like the name say its to dismiss something from a List. There is an issue which suggests to make it possible to avoid deleting the entry from the ListView directly. However, this is inactive. I don't know whether this feature is there or where it is on the priority list.
dismissible
If you use a prebuild and static list of widgets you can maybe get around it, by navigating to the naw page in the onDismissed: callback and using pushReplacement in the rout back. This will case your main page to get Rebuild. Because your Widgets are static I think they will be their again.
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => Page1(),
),
);
flutter_slidable
There is a plugin called flutter_slidable perhaps a solution can be found with this plugin.
I am trying to create a screen like below which will allow user to show few buttons on top of another screen . So basically it will be on top of another screen which can be seen from the half transparent screen of the top level screen. Not sure how to create it and which widget to use. Can someone please guide here. I am trying to do this using flutter to create android as well as ios app.
You are looking for the stack widget here, develop your first screen and another one which you want to put on top. Put both in stack widget so one can come on top of another one.
On the screen which should be on top, make the first half of it transparent (which can be attained in different ways, one of it would be to use a Card with elevation of 0).
The most accurate answer would be do use an an showModalBottomSheet which we expand from the button into the screen and will also color the screen darker. Example code could be following:
await showModalBottomSheet<void>(
isScrollControlled: true,
context: context,
backgroundColor: Colors.white,
builder: (BuildContext context) {
return Container(width: MediaQuery.of(context).size.width, height: 200);
},
)
With the current answer you would have to write the entire funtionality for it by yourself, which could be quite unnecessary when there is already a widget out there for exactly this case
I noticed that in iOS 13 full screen dialog has changed, introducing a new slide from bottom animation.
Here is an example
Is it possible to mimic this behaviour with flutter? iOS animation it's not a simple slide from bottom but involves also the background page.
Looking throught flutter documentation I found this class but, without any example I can't understand how to use it or if it's what I'm searching.
Thanks
Update: Based on another answer by #VadimKo, I now understand that the stacking effect might also be desired. The answer linked to a package modal_bottom_sheet based on which I have updated my example
If I'm understanding your question right, you want to show a full screen dialog that slides up from the bottom and has UI similar to the one showed in your picture.
CupertinoFullscreenDialogTransition is really just two SlideTransitions stacked up so it's nothing special.
You could achieve something close to the posted images by using showGeneralDialog
In that, you could show anything using the combination of pageBuilder and transitionBuilder. It's very flexible and can even be used to show full routes on top of current route.
If you use CupertinoFullscreenDialogTransition as the pageBuilder it should achieve your goal. It's not required to provide a transitionBuilder since it's being performed by the pageBuilder implicitly.
The following example tries to mimic requested UI by using CupertinoApp, CustomScrollView and CupertinoSliverNavigationBar for the content of the dialog
Update: A transitionBuilder similar to the one provided by modal_bottom_sheet can be used to add the stacking effect.
Important code from the DartPad example:
showGeneralDialog(
barrierDismissible: true,
barrierLabel: 'Settings',
barrierColor: Colors.black,
context: context,
/// This would be slow but good to understand how transitions are working
transitionDuration: const Duration(seconds: 1),
/// Optionally provide the [transitionBuilder] to get the stacking effect
/// as of iOS 13
transitionBuilder: (context, animation, secondaryAnimation, child) {
/// The following transition widget was inspired from `modal_bottom_sheet` package
/// Some modifications have been made to remove certain limitations,
/// See the full DartPad example or take a look at `modal_bottom_sheet`
return _CupertinoModalTransition(
animation: animation,
child: child,
/// This renders the current widget behind the modal
/// Notice the use of [this], it is to make sure correct context is used
behindChild: this.build(this.context),
);
},
pageBuilder: (context, animation, secondaryAnimation) {
/// This is the simplest use case for [CupertinoFullscreenDialogTransition]
/// This provides the slide up and slide down transition effects
return CupertinoFullscreenDialogTransition(
primaryRouteAnimation: animation,
secondaryRouteAnimation: secondaryAnimation,
/// Content of your dialog
child: Container(),
linearTransition: true,
);
},
);
DartPad Full example : https://dartpad.dev/57de88ce8d64dff9d3e6fe0627a8b654
Update: The DartPad example works just like modal_bottom_sheet but without any need to make changes to existing code such as the requirement to use MaterialWithModalsPageRoute or to wrap current/preview routes in CupertinoScaffold both of which are provided by the same package.
Preview:
See the GIF preview: https://i.imgur.com/mZ77M62.gifv
Note: There is already showCupertinoDialog provided by the flutter team but it doesn't provide as much flexibility. It can however be used for normal small dialog popups that don't usually take full screen space.
You can always build your own widgets, however in this case you can use an existing package: Modal bottom sheet
you can also check some more existing flutter issues here: enter link description here
You can use this package cupertino_fullscreen_modal
CupertinoFullscreenModal.of(context).showModal(Widget child, onClose (popValue) {});
You can also try another already existing package Cupertino Stackview
CupertinoStackView(
true, //_isPrimary
"Page I", //_navigation
Scaffold(...), //_child
Colors.black, //_backgroundColor
{Key key,
isDismissible : true,
radius : Radius.circular(10.0)})