Hello I am trying to show some data to user with ListView but I get exactly this error:
*RenderFlex children have non-zero flex but incoming height constraints are unbounded.
My Code is Exactly Like Below,
Expanded(child:
ListView(children:tWidgets),),]);
My Code works fine without ListView like this
return Column(children: tWidgets,);
Expanded Widgets only work inside Row and Column widgets, they cannot be used outside of these two widgets, so your solution will be like this
return Column(children: [
Expanded( child: ListView(children: tWidgets,),)
],
);
try
ListView(
shrinkWrap: true,
https://api.flutter.dev/flutter/widgets/ListView-class.html
I solved this issue by fixing the order of my interface.
ListView was inside a Column and that column was also inside another column. I simply deleted a column.
if you are facing with this problem check the hierarchy of your interface.
Related
I want to add a similar item between my SliverAppBar and SliverList. I tried using a regular Row, but it kept throwing an exception. I know about SliverPadding, so I was wondering if there's something similar. Any help would be greatly appreciated.
try SliverToBoxAdapter, reference:
SliverToBoxAdapter(
child: Row
)
Let's say I have this Column:
Column(
children: [
Flexible(
flex: 2,
child: Card(
child: Text("Card")
)
),
Flexible(
flex: 3,
child: Column(
children: [
// Buttons
]
)
)
]
)
What I want to achieve is that the Card always has a flex of 2, and only gets smaller if the screen (or parent) is too small to render both the card and the buttons. However, with the code above, the card gets scaled down to its minimum size to contain the text, although there is space at the end of the screen.
Replacing the card's Flexible widget with an Expanded widget would fix this, but as I already said, it will never get smaller then, which will end up in a bottom overflow if the screen gets smaller (or the buttons get bigger).
Is there any way to achieve what I want? Or is this just a limitation of Flutter's rendering system?
Edit: I want to avoid making the screen scrollable.
As you probably already know, Flexible allows its child to expand, but it does not force to do so. Viceversa, we use Expanded to force a child to occupy the remaining column/row.
Here's your options:
Use a Flexible Widget, and exploit its fit property: set it to FlexFit.tight to force it to fill the space (default is FlexFit.loose: the child can be at most as large as the available space, but is allowed to be smaller);
Use an Expanded Widget, since I sense that you want to occupy all the available space, a priori;
Mix these two approaches (Flexible on your Card, Expanded on your Buttons, or vice-versa)
In both cases, if some smaller screens are giving you trouble, consider making some elements scrollable: I don't know how big your Card is, but you could wrap it inside a SingleChildScrollView. Or, if you want try something else, you could make the whole screen scrollable with the same approach (you have to pay attention to that Column, though, as there is infinite height...)
I used ListView inside Column and it causes a rendering error. When I wrapped ListView in Container or Expanded widgets, it works fine. What is the reason that causes the error?
Column(
children: <Widget>[
Expanded(
child: ListView(
children: <Widget>[
],
),
),
],
),
A ListView tries to fill all the available space given by the parent element (here column). But the column has no definite space defined.
Column's children should have a definite size. If you haven't used Expanded or shrinkWrap property of listview, it won't recognize. Hence will give you rendering error.
With Expanded, you defined that child can expand as much as it wants, giving the definite size.
Or
If you set it to shrinkwrap: true, the list will wrap its content and be as big as its children allow it to be.
So in both cases, the column will get a definite size to render.
exchange
I want to add in my project this. How can i do something like that or similar?
U can use row widgets for this and nest them
Row(
Row()
Row()
)
Use listview builder to display all the set of rows
Eg question Flutter nested Rows MainAxisAlignment
I tried to create add an image to my ListView by doing the following
new ListView(
children: <Widget>[
new NetworkImage('my_image_url')
]
)
and got the following error:
The element type 'NetworkImage' can't be assigned to the list type
'Widget'.
NetworkImage isn't a Widget, instead it:
Fetches the given URL from the network, associating it with the given
scale.
Thus, it's used in Widgets like CircleAvatar to provide the source for its image.
The correct way to add an image via a url is to use Image.network('url'):
new ListView(
children: <Widget>[
new Image.network('my_image_url')
]
)
NetworkImage doesn't just:
Fetches the given URL from the network, associating it with the given scale.
It can be used to display an image. In fact you will need it for something called DecoratedBox, which IS a Widget.
Compared to the simple Image.network('my_url'), using DecoratedBox has a few advantages. Because you can alter that image.
You have access to filters, slice, shadows, or even borders.