Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal button group in Flutter

I am trying to build a horizontal button group using flutter but the I didn't get as far as desired, I am new when it comes to building UIs using dart, how can I tweak the code to achieve the desired result ?

Below you will find my current progress and the desired result!

current row of buttons

//Horizontal buttons row    
            Wrap(                  
              direction: Axis.horizontal,
              children: <Widget>[
                ButtonTheme(
                  minWidth: 40.0,
                  child: RaisedButton(
                    color: Colors.white,
                    onPressed: () {},
                    child: Text("A"),
                  ),
                ),
                ButtonTheme(
                  minWidth: 40.0,
                  child: RaisedButton(
                    color: Colors.white,
                    onPressed: () {},
                    child: Text("B"),
                  ),
                ),
                ButtonTheme(
                  minWidth: 40.0,
                  child: RaisedButton(
                    color: Colors.white,
                    onPressed: () {},
                    child: Text("C"),
                  ),
                ),
                ButtonTheme(
                  minWidth: 40.0,
                  child: RaisedButton(
                    color: Colors.white,
                    onPressed: () {},
                    child: Text("D"),
                  ),
                ),
                ButtonTheme(
                  minWidth: 40.0,
                  child: RaisedButton(
                    color: Colors.white,
                    onPressed: () {},
                    child: Text("E"),
                  ),
                ),
                ButtonTheme(
                  minWidth: 40.0,                     
                  child: RaisedButton(
                    color: Colors.white,
                    onPressed: () {},
                    child: Text("F"),
                  ),
                ),
                ButtonTheme(
                  minWidth: 40.0,
                  child: RaisedButton(
                    color: Colors.white,
                    onPressed: () {},
                    child: Text("G"),
                  ),
                ),                        
              ],
            )

given result: enter image description here

desired result enter image description here

like image 756
Thorvald Avatar asked Aug 28 '26 16:08

Thorvald


2 Answers

Here's how I did it:

Widget specialCharsPanel() {
  return Container(
    child: Material(
      elevation: 4.0,
      borderRadius: BorderRadius.all(Radius.circular(6.0)),
      child: Wrap( 
        direction: Axis.horizontal,                    
        children: <Widget>[
          SpecialChar("A"),
          SpecialChar("B"),
          SpecialChar("C"),
          SpecialChar("D"),
          SpecialChar("E"),
          SpecialChar("F"),
          SpecialChar("G"),                 
        ],
      ),
    ),
  );
}
like image 190
Thorvald Avatar answered Aug 31 '26 08:08

Thorvald


you could use ToggleButtons that is more accesible and compatible with tabindex in web and desktop https://api.flutter.dev/flutter/material/ToggleButtons-class.html

https://www.youtube.com/watch?v=kVEguaQWGAY

like image 37
Mauro Zadunaisky Avatar answered Aug 31 '26 08:08

Mauro Zadunaisky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!