How to pop CupertinoPageRoute with swipe down? - flutter

Currently I'm using the following Code to get a FadeInTransition from the bottom when opening the page.
Navigator.of(context).push(
CupertinoPageRoute(
fullscreenDialog: true,
maintainState: true,
builder: (BuildContext context) => Routines(),
)
)
Normally in iOS you can just swipe left to close the current page. Is there an easy way to swipe down to pop the current page or do I have to implement a custom field with a GestureDetector()?
The goal is to have a closing transition like in the GIF below using a swipe down at the top
I considered using a DraggableScrollableSheet but I don't want to slide the Page into view from the bottom.

I ended up solving it with an DraggableScrollableSheet:
onPressed: () {
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return Routines();
},
);
},
and Wrapping my new Page with:
return DraggableScrollableSheet( //TODO make same for Entries
expand: false,
initialChildSize: 1.0,
minChildSize: 0.8,
builder: (context, scrollController) {
return Page2();
}
);

Related

modalBottomSheet + ListView, how to sync scroll?

I have a modalBottomSheet with a scrolling list view inside of it.
I want for the scroll control to be transferred to the bottom sheet when the listView reaches the top, so that it can be dragged to dismiss.
Now, the listView gets to the top and even if I keep dragging the bottom sheet will not be dismissed on drag.
Thank you!
Try this way
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) {
return DraggableScrollableSheet(
maxChildSize: 1,
initialChildSize: .5,
expand: false,
builder: (context, scrollController) {
return ListView.builder(
itemCount: 44,
controller: scrollController,
itemBuilder: (context, index) => ListTile(
title: Text("item $index"),
),
);
},
);
},
);

I want a similar screen (one on top of other) like following to complete my weather app made using flutter . Can anyone please help me out?

I want this type of screen one on top of other and the previous screen should be lightly blurred or it should slightly darkens
You could use 'ModalBottomSheet' or even 'DraggableScrollableSheet' if a list is associated.
ModalBottomSheet
showModalBottomSheet(
context: context,
builder: (context) {
return Container(
// widgets
),
);
});
DraggableScrollableSheet
DraggableScrollableSheet(
builder:
(BuildContext context, ScrollController scrollController) {
return Container(
// widgets
);
},
),

My modalBottomSheet is draggable just on edges

I have a DraggableScrollableSheet inside of a showModalBottomSheet builder. I have set isDismissible: true for modal sheet but my widget is draggable just on edges. That is because I have a ListView inside of DraggableScrollableSheet.
What I should do for when the list is overscrolled on top the drag to start?
Here goes my code:
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
isDismissible: true,
backgroundColor: Colors.transparent,
enableDrag: true,
builder: (BuildContext context) {
return StackedSheet(
backgroundColor: backgroundColor,
onBackgroundColor: onBackgroundColor,
padding: padding,
minChildSize: minChildSize,
maxChildSize: maxChildSize,
onClose: onClose,
child: SafeArea(
top: false,
child: child,
),
);
},
);
Where StackedSheet is:
LayoutBuilder(
builder: (context, constraints) {
return DraggableScrollableSheet(
key: Key('$_childSize'),
initialChildSize: min(_childSize, widget.maxChildSize),
minChildSize:
min(_childSize - _childSize * 0.2, widget.minChildSize),
maxChildSize: min(_childSize, widget.maxChildSize),
expand: false,
builder: (
BuildContext context,
ScrollController scrollController,
) {
return ListView.separated( ...blah blah)
}
Here is a GIF:
Instead of bouncing, my desire is to start to be dragged down.
In my opinion you can use scroll controller to dismiss bottomsheet on reaching top something like this
if (_controller.offset <= _controller.position.minScrollExtent &&
!_controller.position.outOfRange) {
.....
.....
);
}
You can stop list from bouncing at top using shrinkWrap=true in Listview.
And to dismiss the bottomsheet you can refer to this stackoverflow post
I haven't tried this code but hopefully it will help you in some way.
Also, I think it will look good if you will keep it the way it is now by inserting a little "-" at top on right side of "X" ,on which user can touch to slide down.

how to prevent flutter showBottomSheet from being dismissed by dragging down?

I am using showBottomSheet in flutter to show a persistent bottom sheet. how can I prevent flutter showBottomSheet from being dismissed by dragging down?
I have added my code below. you can place a rawmaterialbutton and with onpressed call this function.
void itemChooser(
{int currentItemCount, String name, callBack, BuildContext context}) {
int chosen = 0;
showBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
height: 500,
color: Colors.white,
);
});
}
Just wrap your child with GestureDetector and set onVerticalDragStart: (_) {},
showBottomSheet(
context: context,
builder: (context) => GestureDetector(
child: *your_widget*,
onVerticalDragStart: (_) {},
),
);
Set enableDrag property of BottomSheet to false its true by default
BottomSheet(
enableDrag: false,
builder: //builder
),
Refer here for more info on BottomSheet
If you use showModalBottomSheet, simply use enableDrag property:
showModalBottomSheet(
context: context,
builder: (context) => yourWidget,
enableDrag: false,
);

How to make CupertinoActivityIndicator top of every layout?

How to make CupertinoActivityIndicator top of every layout?
i need to show progress bar on when login and home page loading time
You could show a dialog like this:
void _showIndicator() {
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => Center(
child: CircularProgressIndicator(),
),
);
}
In this example, I am using CircularProgressIndicator, but you could replace that with CupertinoActivityIndicator. When you want to dismiss the indicator, call:
Navigator.pop(context);