I want to make view with 6 buttons in 2 rows ( 1 row – 3 buttons).
My problem is the buttons dont take all free space.
Probably row is limiting space but i dont know how to fix it.
I was trying to use Expanded but it not help.
It must be buttons or something else wchich have onPress action and frame with color wchich i can change.
https://imgur.com/IzKGX0D
return Scaffold(
backgroundColor: Colors.green,
body: Container(
child: Column(
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
Expanded(
child: OutlinedButton(
child: Text('test'),
onPressed: () => null,
),
),
Expanded(
child: OutlinedButton(
child: Text('test'),
onPressed: () => null,
),
),
Expanded(
child: OutlinedButton(
child: Text('test'),
onPressed: () => null,
),
)
],
),
),
Expanded(
child: Row(
children: <Widget>[
Expanded(
child: OutlinedButton(
child: Text('test'),
onPressed: () => null,
),
),
Expanded(
child: OutlinedButton(
child: Text('test'),
onPressed: () => null,
),
),
Expanded(
child: OutlinedButton(
child: Text('test'),
onPressed: () => null,
),
)
],
),
)
],
),
),
);
2
Answers
That’s because you are using a predefined widget
OutlinedButton
that has some constraints, that’s what you see the height is fixed.The beauty of Flutter is you can create any widget you want, this is a sample widget I created for you:
Now just replace
OutlinedButton
byMyOwnButton
(or change the name if you want).Example:
Result:
Dartpad sample: https://dartpad.dev/?id=0802859474f1a2f855e9153141302bce
Of course you can change the color of the borders or background.
if i understand your question correctly, you want to your button get all possible width and height.
for this you can set Style to your buttons.
for instance one of your button convert to this:
because of "Expanded" min width(40) ignore in rendering.
or your can create stateless custom view and handle it by yourself.