Athul A
Athul A

Reputation: 195

How to remove margin on flutter IconButton or other Buttons?

The Default Margin of Buttons is adaptive according to the PlatForm they are used. On Desktop Apps these seems to have no marging and on android, ios it has margin, how to fix this

I have tried changing the Visual density, adjusting the BoxContraints, etc by referring to this and those does not work.

Upvotes: 0

Views: 93

Answers (2)

Bhavesh Vaghasiya
Bhavesh Vaghasiya

Reputation: 119

Easy Method. Please review this code

IconButton(
 padding: EdgeInsets.zero,
 constraints: BoxConstraints(),
 icon: Icon(Icons.access_alarm),
 onPressed: () {},
)

ElevatedButton(
   style: ElevatedButton.styleFrom(
   padding: EdgeInsets.zero,
   minimumSize: Size.zero,
   tapTargetSize: MaterialTapTargetSize.shrinkWrap,
 ),
  onPressed: () {},
  child: Text("Click Me"),
)

Upvotes: 1

Athul A
Athul A

Reputation: 195

The actual solution is to use tapTargetSize: MaterialTapTargetSize.padded for margin and tapTargetSize: MaterialTapTargetSize.shrinkWrap for removing the margin. Hope this helps.

You can also define materialTapTargetSize: MaterialTapTargetSize.padded on your ThemeData to set margin accross the app for all supported widgets.

Upvotes: 0

Related Questions