Home > Software engineering >  How add buttons horizontally in flutter
How add buttons horizontally in flutter

Time:09-10

I'm a beginner and trying to add 3 buttons horizontally I have added but they don't contain "match parent" like in android.

my code  
Row(
                       mainAxisAlignment:MainAxisAlignment.spaceBetween,
                        children: [
                          ElevatedButton(onPressed: () {}, child: const Text("Male")),
                          ElevatedButton(onPressed: () {}, child: const Text("Female")),
                          ElevatedButton(onPressed: () {}, child: const Text("Other")),
                        ],
                      ),

you can view the image image

CodePudding user response:

Wrap each button in an Expanded.

Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: [
    Expanded(child: ElevatedButton(onPressed: () {}, child: const Text("Male"))),
    Expanded(child: ElevatedButton(onPressed: () {}, child: const Text("Female"))),
    Expanded(child: ElevatedButton(onPressed: () {}, child: const Text("Other"))),
  ],
);

CodePudding user response:

Have Multiple solutions.

Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: [
   
  ],
);

Second is.

Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: [
  Text("Male"),
  SizedBox(width:10.0),
  Text("Male"),
  SizedBox(width:10.0),
  Text("Male")
  ],
);

And to solve Row Overflow Use Wrap.

  • Related