Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a gap between ToggleButtons in Flutter

I have these ToggleButtons and I want to make them appear with some spacing between them.

ToggleButtons(
  children: <Widget>[
    Icon(Icons.ac_unit),
    Icon(Icons.call),
    Icon(Icons.cake),
  ],
  onPressed: (int index) {
    setState(() {
      isSelected[index] = !isSelected[index];
    });
  },
  isSelected: isSelected,
),

The desired result is this:

enter image description here

Is this possible somehow?

like image 716
Foti Dim Avatar asked Apr 10 '26 17:04

Foti Dim


1 Answers

The key is to remove the default Toggle Button border,fill color and add them separately.

renderBorder: false
fillColor: Colors.white,

Then add a padding over the widget but

ToggleButtons(
       renderBorder: false,
       fillColor: Colors.white,
       onPressed: (val) {
        setState(() {
                    itemStatus = List.generate(3, (index) => false);
                    itemStatus[val]=!itemStatus[val];
                  });
        },
        children: List<Widget>.generate(
        3,
       (index) => Padding(
       padding: const EdgeInsets.all(8.0),
       child: Container(
       decoration: BoxDecoration(
       **color:itemStatus[index]? Colors.amber:Colors.white,**
       border: Border.all(),
      borderRadius: BorderRadius.circular(10),),
      padding: const EdgeInsets.all(5),
      width: 160,
      height: 70,
      alignment: Alignment.center,
     child: Text(itemTypes[index],style:const  **TextStyle(color: 
      Colors.black)**,),
     isSelected: itemStatus
),

like image 169
Chanaka Eranga Avatar answered Apr 13 '26 07:04

Chanaka Eranga



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!