I have been searching for a way to scroll to the bottom of the ListView widget automatically after retrieving data from firebase database. I have seen a number of solutions but they do not work for me.
I find that scrollController.postion.maxScrollExtent is always 0.0. I don't want to use the reverse property of the listView either as that doesn't give me exactly what I want even though very close.
Below is a snippet of the code. When I use chatController.position.maxScrollExtent the value is 0.0 and not the value of the size of the ListView. If I use a listener that listens to scrolls then I see the value of chatController.position.maxScrollExtent but that is not the behaviour I want. I don't want to manually initiate a scroll for the app then go to the bottom of the list. It must do that as I open the app.
Any help will be greatly appreciated. Thanks
Container(
child: Column(
children: <Widget>[
Expanded(
child: ListView(
controller: chatController,
//shrinkWrap: true,
children: [getConversation()], //list of chats wrapped in a Column widget
)
),
)
Related
I am use Flutter for web for make website. I need make foreground scroll, but background not scroll like normal website. For example: codemagic.io .
I cannot use Scaffold background because I want use use CustomPainter for custom background.
I am try use Stack, but issue is I need Center Widgets in ScrollView, and if I do this then the CustomPainter is not start from top of page:
Stack(
children: <Widget>[
Center(
child: SingleChildScrollView(
child:
Stack(children: <Widget>[
CustomPaintWidget(),
Widgets(),
],),
Anyone know solution?
Thanks!
You have two stacks here and one is only holding one widget (basically pointless for what you want to do). Put a widget on the bottom index of that stack (0) and make it the size of its container. You could use LayoutBuilder to get the size of its parent widget. Then place the singlechildscrollview on top of that.
I want to only make a part of my screen scrollable. When the number of items in my ListView exceeds 4 or 5 I am unable to place any widgets below this list view. I am not sure if there is a way to wrap all the contents of the listview to make that scrollable.
ListView(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
children: _getListings(businessListing),
),
This is my ListView and this is how the UI looks
The problem is when the number of RadioTile exceeds 8; the textField and the Button are pushed out of the screen.
I am wondering if it is good to make the entire screen scrollable?
Or make only a part of the screen containing the RadioTiles Scrollable?
Thanks,
To complete thebuggycoder answer if you want to keep only a part of your screen scrollable but keep variable height bottom elements, you can embed your ListView inside the Expanded of a Column, as shown below:
Column(
children: [
Expanded(
child: ListView(
children: _getListings(businessListing),
),
),
Container(
child: Text('This element must stay at the bottom'),
),
],
);
What are you doing there is basically telling your Column that it has 2 (or more) elements where each element usually takes the space it needs, except elements that are Expanded elements and will take "the maximum space left" in the Column.
There are a couple of points to consider:
If you plan to have more fields below the RadioTiles along with the Google Listing URL and the Save button, then it might be a good option to keep the entire screen scrollable.
On the other hand, if it's going to be just the two things below the RadioTiles, then it would be better to keep only the RadioTile list to be scrollable. This way the TextField and the Save button will always be accessible to the user without the need to scroll.
Also, you can decide about the scrolling depending on the priority of the fields. If the TextField and Save button have more priority then it would be best if they are always visible on the screen.
To make only a part of the screen scrollable, you can wrap the ListView in a Container with some fixed height, so that the it will scroll only within those bounds.
You will also need to change the physics property to AlwaysScrollableScrollPhysics().
Example -
Container(
height: 300.0 //Your custom height
child: ListView(
shrinkWrap: true,
physics: AlwaysScrollableScrollPhysics(),
children: _getListings(businessListing),
),
)
I have a login screen with a logo on top. I want the login form to be exactly in the screen center (not in the center of the space below the logo). So far I managed to achieve that using Stack, roughly like this:
Stack(
children: [
Positioned(
child: Logo(),
left: 0,
top: 0,
),
Column(
children: [LoginForm()],
mainAxisAlignment: MainAxisAlignment.center,
),
],
)
In general, I am quite happy with how it looks, however, when the soft keyboard pops up, the visible screen size and the notion of the center change, the form moves up and overlaps with the logo. I know I can prevent widgets from resizing at all, but can I just allow the form move up only as long as it does not overlap with the logo?
You can use ListView instead of Column that will avoid overlapping with the logo and when keyboard opens, it will automatically scroll up the form.
Also note that, once you use ListView, use shrinkWrap: true inside it, as it'll only occupy the space it needs.
Hope this answer helps.
I'm looking for an example that would show how to implement simple drawer menu and master/details screen. I currently have a solution, but it has a flaw. The issue is that when an item in master list view is clicked, the whole drawer is replaced by details screen.
I would like to have drawer always visible.
Is there simple example for this? I haven't found one :/
Thank you!
It seems like a drawer that is always visible is just a Row item?
Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
width: 240.0,
child: <master>,
),
Expanded(child: <detail>),
],
)
I have discover that this is not optimal solution. Best practise shows that opening details always hides drawer menu like in Gmail or other Adndroid apps..
I need some help with a layout.
I need put some widgets inside a "Scrollview" but keep the buttoms in the bottom space of screen.
Image with a "Scrollview" with some textFields inside, and under de "Scrollview" a Rows containing two buttons
So if I change orientation the Layout will keep buttons at bottom and will scroll the widgets above.
How can I made it in flutter, I tried to use the Stack, Listview and others approaches, but i didn't have luck
Multiple ways. I recommend you either using a Scaffold or a Column:
If you are already using a Scaffold in your app, just add bottomNavigatorBar as a Parameter, your bar you want to have at the bottom in it and make sure the rest of your layout is located under it's body tag.
Otherwise you could use a Column:
Column(
children: <Widget> [
Expanded(child:ScrollView(..),),
yourBottomBar,
] )
Or Flutter also has a Positioned widget which you can use in combination with a Stack:
Stack(
children: [
// some stuff
Positioned(
bottom: 0,
child: yourBottomBar
),
],
)