Containers with dynamic sizes inside a listview widget - flutter

I'm creating a listview widget and i want it to have varying container sizes that change from user inputs inside it, the problem is when i wrap my columns or rows in expanded widgets, the code breaks.
is there a way to set a min and max height for a list view widget?
ListView(
children: [
Column(
children: [
Row(
children: [
Expanded(
child: Container(
color: Colors.yellow,
),
),
Container(
width: 2,
color: kKillTeamOrange,
),
Expanded(
child: Container(
color: Colors.green,
),
),
],
),
],
),
],
),
I tried wrapping the listview in a constrained container but no luck, the other option would be to have the buttons set the height state but there are a lot of buttons to code that. and using expanded widgets is great for varying screen sizes.
any help would be greatly appreciated.
cheers

Two ways came to mind:
CustomScrollView
ListView (But using cards)
Both ways are responsive to screen sizes
LISTVIEW WITH CARD:
CUSTOM SCROLLVIEW:
RESULT:
hope this helps...

Related

In Horizontal List view builder how to use container without declaring height

In container I am using list view builder, while I am using Axis.horizantal without declaring height of I am getting render box layout issue
you can use the combination of SingleChildScrollView and Row to replicate the Behaviour of Listview with horizontal Scroll.
An example is mentioned below, this one worked for me.
Container(
color: Colors.black,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: const [
Icon(Icons.phone),
],
),
),
),

Making a container scrollable

I have this view in my app
and this is the code for it:
return Container(
color: Colors.black,
child: ListView(
children: <Widget>[
Column(
children: <Widget>[
...
],
)
],
),
);
But if I click on my form I get stuck and the list of items is hidden by the keyboard, so I'd like to make my Container scrollable.
How can I do?
Instead of wrapping your Column with a ListView try with a SingleChildScrollView instead. You can also try adding a bottom padding equal to keyboard size MediaQuery.of(context).viewInsets.bottom.

How to make equal width or height constraints between widget in flutter?

In iOS's native AutoLayout constraints, It very easy to make a equal width constraints between ViewA and ViewB . And these two views will get a same width always.
But in flutter ,it seems can't be achived this kindof constraints so easily?
Do I have to make a SizedBox with specific width for both WidgetA and WidgetB explicitly?
You can always put your widgets in a Row(), and wrap every widget in Expanded(). This way they will always have 50% width of the parent Row(). And if you need to constrain the width, just wrap the Row() in a SizedBox().
SizedBox(
width: 500.0,
child: Row(
children: [
Expanded(
child: Container(),
),
Expanded(
child: Container(),
),
],
),
),

Flutter: How to adjust the height of a container as the maximum height of its sibling in a row

I have two widgets in a row. The first widget is a black line with width 5.0, the second widget is a text widget whose size may vary according to the content. I want the first container to have the same height as of the second widget
One way is to make both widget child of an IntrinsicHeight widget and then declare the height of the first container as double.infinity. This should solve your problem. Example code is given below:
IntrinsicHeight(
child: Row(
children: <Widget>[
Container( //this is the first container
height: double.infinity
),
secondWidget(
)
],
)
Let me know if you have further query. Happy coding!
You can use Expanded widget. It divides siblings to the same height or width.
here is the code:
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.red,
),
),
Expanded(
child: Container(
color: Colors.green,
),
)
And here is the result:
That is so easy. I wish it could help.

Flutter: how to center a child, but set a limit on how big it can grow on one side of the margin

I have a home/login screen which is made up of a column that fills the entire screen like so:
Column(
children: <Widget>[
Expanded(
child: Container(
child: Logo(),
),
),
showThis ? This() : That(),
],
),
The second child of the column is dynamic and can have different heights, and this screen will have inputs so the keyboard will also affect the height.
I want to center Logo() vertically within the container when it's small (e.g. when keyboard is active), but limit how much the 'top margin' is able to grow, so that when the keyboard is hidden and This()/That() is small enough, Logo() will be in a static position on the screen, say 150 from the top (no longer centred vertically).
One method I have tried was using 2 empty Expanded() above and below Logo() and wrapping the top part in a ConstraintedBox(), but I am not able to get it to behave correctly.
Have you tried with Center() and also if you wanna in a specific position use Stack, for example
Stack(
children: <Widget>[
showThis(),
Positioned(top: 150, child: Logo())
],
)
This is what ended up working for me:
Column(
children: <Widget>[
Expanded(
child: Column(
children: <Widget>[
// constrain top spacing with a max height
Flexible(child: Container(height: 160)),
_logo(),
Spacer(),
],
),
),
_bottomWidget(),
],
),