I'm reviewing the Flutter 'modal_bottom_sheet' package, and I'm wondering if there is a way to set the maximum width of a modal bottom sheet?
In my case, this is a web app, so I don't want the popup modal to take the full browser width
Try to set a constraint
showModalBottomSheet(
context: context,
constraints: BoxConstraints(
maxWidth: 500
),
builder:
)
Related
I'm using flutter's latest version to create a bottom model sheet with a text field which is auto focused, so as soon as I click the button to show that bottom model the UI lags while soft keyboard appears. I've tried setting the following property to false, but still no luck.
Scaffold(
...
resizeToAvoidBottomInset: false,
)
Here's the code bottom sheet is being called:
floatingActionButton: FloatingActionButton(
onPressed: () async {
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) => const TaskBottomSheet());
}),
There's no lag until I make the soft keyboard appear in the screen. How can I fix this?
Did you try to run it in the profile or release mode? Flutter optimizes your app in these two modes.
flutter run --profile or flutter run --release
I used two listView inside listview,when i put the overall listview inside the pageview, the pageview is not scrolable
Instead of using Listviews inside each other, I suggest you to use a GridView. I think your ListViews have different directions. If they do, GridViews will help you.
Other solution, if you insist on using ListView, then wrap the ListViews with ConstrainedBox then give them BoxConstraints
ConstrainedBox(
constraints: BoxConstraints(maxHeight: 100, maxWidth: 200)
child: ListView(),
)
You should adjust maxHeight and maxWidth in the proper size.
Hope this helps.
it looks like you are looking for sliverlist
SliverList & SliverGrid
or sliver tool
sliver_tools
I have no idea to figure out this problem in flutter. I want to know the size without app bar size and tab bar size(up).
I use variable "vertical_size" as
var vertical_size = (MediaQuery.of(context).size.height -
AppBar().preferredSize.height -
MediaQuery.of(context).padding.top);
but I didn't figure out the tab bar size. It's mean there are oversized in Iphone. (Android is okay in now...)
Do you have any idea to measure tabbar height using Mediaquery? Or is there any idea to measure the actual using area?
You can always figure out the free space in any place you want in your layout with LayoutBuilder
In case of full usable screen height, you can use MediaQuery, but aparat from appbar's height and top padding, remember about bottom padding. You need to substract it as well
Hi and welcome to StackOverflow.
It's not oversized in iOS. What happens is that the AppBar will have in consideration the safe area, hence, its heigh will be bigger/smaller based on the device it is running on.
If you want to get the height of the screen without the AppBar heigh, just do it as the following:
Widget build() {
AppBar appBar = AppBar();
double vertical_size = MediaQuery.of(context).size.height - appBar.preferredSize.height;
return Scaffold(
appBar: appBar,
body: // your widget
);
}
The AppBar's height will have in consideration the device's status bar and so on, so there's no need to remove the inset padding manually.
I have an flutter web-app, it works for all screen sizes. I assigned an variable "width" to get the screen width and based on that entire app is built.
When I Zoom in or out on chrome, it requires me to refresh the page to get the desired sizes. Unless I refresh the widgets don't resize.
I want a certain trigger like functionality, where if there is change in width, the app must rebuild.
How can I achieve this ?
You can use a LayoutBuilder to achieve this. This widget has a builder parameter that is called as the layout constraints change.
LayoutBuilder(
builder: (context, constraints) {
},
)
The constraints provide options that allow your application to understand how much space is available
constraints.maxWidth; // get maximum available width
constraints.maxHeight; // get maximum available height
constraints.minWidth; // get minimum available width
constraints.minHeight; // get minimum available height
These can be used to conditionally change the layout based on the available space and rebuilds at layout time.
Alternatively, you can use a simply MediaQuery. You can get width:
MediaQuery.of(context).size.width;
and height:
MediaQuery.of(context).size.height;
However, these calls must be done in the build method for the sizes to change with each rebuild.
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