remove padding of switch button in flutter

Viewed 299

default switch button in flutter have padding, I want reduce padding, I tried everything I know but I still can't do it

default

I want

I made it

Switch(
    materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
    value: !state,
    activeTrackColor: PrimaryColor.value,
    onChanged: (value)=> context.read<SettingRo>().change(value),
),


 
1 Answers

You can use Material Button or Inkwell or Button theme for this.

Solution 1:MaterialButton/RawMaterialButton:

MaterialButton(
  onPressed: () {},
  color: Colors.red,
  minWidth: 0,
  height: 0,
  padding: EdgeInsets.zero,
  child: Text('Material Button'),
)

Solution 2 Inkwell:

InkWell(
    child: Center(child: Container(child: Text("Inkwell"))),
    onTap: () => onPressed()
);

Solution 3: wrap the button in a ButtonTheme.

give maxWith and height (set to zero to wrap the child) and then pass your button as the child.

ButtonTheme(
  padding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 6.0), //adds padding inside the button
  materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, //limits the touch area to the button area
  minWidth: 0, //wraps child's width
  height: 0, //wraps child's height
  child: RaisedButton(onPressed: (){}, child: Text('ButtonTheme')), //your original button
);
Related