I have one image in a row and a text next to that image. I want the row to expand fully and image takes as its size, then remain full area should be taken by Container.
Here is my code snippet:
Row(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(10, 50, 10, 8),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color.fromARGB(100, 0, 0, 0),
blurRadius: 5,
),
],
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Column(children: <Widget>[
Image.asset(
'assets/card.png',
height: 62,
width: 62,
fit: BoxFit.cover,
)
]),
Container(
child: Text("Hello world"),
)
],
),
),
],
),
I want it like this:
Full-width container using MediaQuery You can also use MediaQuery to assign 100% width to a Flutter Container widget. We can calculate the full width of the device using MediaQuery. A simple Flutter example to make a Container occupy the full width.
You can make the children of Row widget, expand to the available horizontal space. All you need to do is, wrap each child of Row widget around Expanded widget.
I recommend you to start building layouts only with Row
and Column
not to get confusing. I often build layouts as follows.
Row
and Column
. And Set mainAxisAlignment
and crossAxisAlignment
property in Row
and Column
.Padding
or Align
, Expanded
etc. You can also use Container
.Reference:
Layout basic:
https://flutter.dev/docs/development/ui/layout
Tips when building layouts:
https://medium.com/@liewjuntung/tips-on-using-android-studio-to-develop-flutter-apps-9e42c047b7f4
I hope you this will help you.
example code:
Widget buildCard() {
return Container(
margin: EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color.fromARGB(100, 0, 0, 0),
blurRadius: 5,
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image.asset(
'assets/card.png',
height: 62,
width: 62,
fit: BoxFit.cover,
),
Padding(
padding: const EdgeInsets.only(top: 12.0, left: 12.0),
child: Text(
"Hello world",
style: TextStyle(
fontWeight: FontWeight.w500,
letterSpacing: 0.8,
),
),
)
],
),
);
}
Use Expanded instead of the Container around the Text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With