I’m currently working on a Flutter project where I need to achieve a specific layout behavior similar to what I can achieve with CSS align-items: end in a flex container. In my CSS example, I have the following code:
<style>
.container{
display:flex;
background:yellow;
height:200px;
width:200px;
flex-flow:row wrap;
justify-content:start;
align-content:stretch;
align-items:end;
}
.item{
width:50px;
background:red;
}
</style>
<section class="container">
<!-- Items here... -->
</section>
Now, I’m trying to replicate this layout behavior in Flutter using the Wrap widget, but I’m facing challenges in achieving the same result. Here’s a simplified version of my Flutter code:
Container(
height: 200,
width: 200,
color: Colors.yellow,
child: Wrap(
alignment: WrapAlignment.start, // I'm unsure how to achieve 'align-items: end' behavior here
crossAxisAlignment: WrapCrossAlignment.end, // This doesn't seem to give me the desired result
direction: Axis.horizontal,
textDirection: TextDirection.ltr,
spacing: 10,
clipBehavior: Clip.antiAlias,
verticalDirection: VerticalDirection.down,
runSpacing: 10,
runAlignment: WrapAlignment.start,
children: <Widget>[
// ... Children widgets here ...
],
),
)
I’ve experimented with various properties of the Wrap widget, but I haven’t been able to achieve the desired ‘align-items: end’ behavior.
I would greatly appreciate any guidance on how to achieve ‘align-items: end’ behavior within Flutter using the Wrap widget or any alternative approaches to replicate this CSS behavior. Thank you in advance for your help!
2
Answers
I found a solution to the issue I posted earlier. When the heights of the items in a
Wrap
widget are equal, the effect ofcrossAxisAlignment
might not be obvious. However, by randomizing the heights of the items, the effect ofcrossAxisAlignment
becomes more apparent.dart code:
Have you tried
WrapAlignment.end
?