I am struggling with making the column scrollable:
Container(
height: double.infinity,
width: double.infinity,
color: Colors.blue,
child: Column(
children: [
Expanded(flex: 2, child...),
Expanded(flex: 5, child...)
]
)
)
I tried wrapping all the widget inside a single child scroll view, I tried a list view and I tried combing layout builder but nothing works
When you use expanded you should have a limited space (height in column and width in row), in your case your height will fit the space in screen.
If you change the column to the scrollview even change it directly to the ListView or swap it with the SingleChildScrollView, you will have unlimited space and you can't use expanded widget, because it wants to fill all possible space, and it is unlimited in scrollview
Related
I have a container with screen width*.9. Inside this container, I currently have the following:
SizedBox(
width: MediaQuery.of(context).size.width * .65,
child: Row(
children: [
Expanded(
child: TextSplitter(
wave.message,
context,
Theme.of(context).textTheme.subtitle2!,
)),
],
),
),
I would like to be able to remove the SizedBox wrapping the Row, so that the widget expands into the rest of the space in the parent container. However, currently, removing the sized box leads me to the text disappearing, and throws
RenderFlex children have non-zero flex but incoming width constraints are unbounded.
Extending this sized box leads to overflowing the parent's width, causing an error as well. Any ideas?
Thanks!
How do you guys solve the following Flutter layout??
I have a screen, where I have to show, as described in the picture: a logo + 3 TextFormFields + 2 buttons + a Container.
Problems:
I need to put all the widgets inside a Column and, the Column inside a SingleChildScrollView so that, when the keyboard pops up, it does not cover the TextFields.
The last widget, the Container, shall take all the remaining screen space on the bottom, but NOT taking more than the screen size. For that, My idea was to use the Expanded widget, so that the Container can expand to the bottom of the screen, but that gives an error:
The following assertion was thrown during performLayout(): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
So I guess my question, in short is, how do I prevent the keyboard to cover the TextFields, while at the same time I force the Container to take all the remaining space on the bottom.
That was my attempt:
SingleChildScrollView(
child: Column(
children: [
Image.asset("assets/images/appLogo.png"),
TextFormField(),
TextFormField(),
TextFormField(),
Row(children: [TextButton(), TextButton()]),
Expanded(child: Container())
],
));
Expanded doesn't know how much size to take. Also the other children don't know their exact size.
Wrap your Image inside a container and give height & width to it. also try wrapping all textfields inside a column or container each.
SingleChildScrollView(
child: Column(
children: [
Container(
width: MediaQuery.of(context).Size.width * 0.4,
height: MediaQuery.of(context).Size.height * 0.2,
child: Image.asset("assets/images/appLogo.png"),
),
Column(
children: [
TextFormField(),
TextFormField(),
TextFormField(),]
)
Row(children: [TextButton(), TextButton()]),
Expanded(child: Container())
],
));
I hope this will work for you.
What I want to achieve is to have a static Container in the left half and a scroll-able list of items on the right half of the screen:
|----------------------|
| | |
| Container | ListView |
| | |
|----------------------|
It is for a desktop app, so I like this layout. My implementation: (appStatWidgets is a list of containers with text)
Row(
children: [
Container(height: 400, width: 400, color: Colors.green),
Expanded(
child: ListView(
children: appStatWidgets,
),
)
]),
But if i do this, the ListView is invisible and I get:
Vertical viewport was given unbounded height.
But I thought, that
Expanded would fix that.
What works is putting SizedBox instead of Expanded, but that gives me static size and I would like it to be flexible.
Use shrinkwrap: true in your list view parameters, to prevent it from having unbound heights.
And for your Sized box to take half the height for example, use mediaQuery to define the height.
i.e
SizedBox(height: MediaQuery.of(context).size.height * 0.50) This will set it's height to 50% of the screen.
and for ListView(physics, use physics: AlwaysScrollableScrollPhysics().
Row(
children: [
Container(height: 400, width: 400, color: Colors.green),
Expanded(
child:SizedBox(
width:100,
heigth:100,
child:ListView(
children: appStatWidgets,
),
)
)
]),
Like this
For a listview in a row, make sure you set the scroll direction to Axis.horizontal and one more thing make sure you provide your listview a vertical bound, so put it in a container with height only.
Wrap the listview with sized box and provide width and height
----------------------------
# Text *
----------------------------
Text in the center
# left of Text and it is variable length
* at the far right and it is variable length
I've tried using spaceBetween but it doesn't seem to work because components width are different
Try this:
Expanded for # in Container with alignment centerRight, Text, Expanded for * in Container with alignment centerRight in Row.
You can use the Expanded widget to achieve this, Using Expanded Widget you can control the width or height of each child in Row or Column Widget
In Your case Use Row Widget with Expanded for each child
For Example:
Row(
children: [
Expanded(
flex: 2,
child: Text("#")
),
Expanded(
flex: 2,
child: Text("Text")
),
Expanded(
flex: 1,
child: Text("*")
),
]
)
Adjust the value of flex value according to your needs and align text to left. right, or center
For more info check out this link and for video: https://api.flutter.dev/flutter/widgets/Expanded-class.html
I am new to flutter and I must say I am impressed comming from a c# background I was able to do a listview in under five mins that were horizontal and contained a few containers.
However, I would like my container to be dynamically showing a List contents what I have so far is a widget building my colours out
Widget horizontalList2 = new Container(
margin: EdgeInsets.symmetric(vertical: 20.0),
height: 200.0,
child: new ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(width: 160.0, color: Colors.blue,),
Container(width: 160.0, color: Colors.green,),
Container(width: 160.0, color: Colors.cyan,),
Container(width: 160.0, color: Colors.black,
child:Text("Test"),
child: Image.network(
'https://flutter.io/images/catalog-widget-placeholder.png',
height: 100,
width: 150
)
)
But as you see I am trying to create another text element I want image then a bit of text and another text much the same way as Netflix would work but it's for a weather app.
Can someone explain how the child elements works can ou not have more than one child in a container cause when i tried this i got the following error. And what I should do to have a second child element of text and base the listview of a Dynamic POCO List
The [child] contained by the container.
If null, and if the [constraints] are unbounded or also null, the container will expand to fill all available space in its parent, unless the parent provides unbounded constraints, in which case the container will attempt to be as small as possible.
You should use Multi-child layout widget, these accept children instead of child. A good example for you might be Row, Column or Stack.
Don't be scared of nesting your Widgets, you'll be doing it a lot!
ListView
Container
Row
Text
Image
Icon
Container
Row
Text
Image
Icon
When you find yourself repeating your widget tree like this, create a custom widget that outputs the subtree. The above might become:
ListView
MyColoredListItem
MyColoredListItem
You can find a full list of Multi-child layout widgets on the flutter docs here:
https://flutter.dev/docs/development/ui/widgets/layout#Multi-child%20layout%20widgets
For more information about creating your own widgets:
https://api.flutter.dev/flutter/widgets/StatelessWidget-class.html
https://api.flutter.dev/flutter/widgets/StatefulWidget-class.html