Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElevatedButton padding on all sides won't modify

Tags:

flutter

I have a ElevatedButton with the following attributes: I attached a photo here: https://i.sstatic.net/oH3pO.png

ElevatedButton(
               clipBehavior: Clip.none,
               style: ElevatedButton.styleFrom(
               padding: EdgeInsets.zero,
               minimumSize: Size(0, 0),
               elevation: 0,
               ),

I modified the padding around and it still has a minimum padding (_InputPadding) of 48px by 48px. How can I solve this?

like image 281
Adelin Preda Avatar asked Feb 16 '26 20:02

Adelin Preda


2 Answers

These paddings are because of tapTargetSize property. To remove them add tapTargetSize: MaterialTapTargetSize.shrinkWrap, to the button style.

For example:

ElevatedButton(
  style: ElevatedButton.styleFrom(
    fixedSize: size,
    padding: const EdgeInsets.zero,
    tapTargetSize: MaterialTapTargetSize.shrinkWrap,
  ),

Additional info from the source code.

  /// MaterialTapTargetSize
  ///
  /// Expands the minimum tap target size to 48px by 48px.
  ///
  /// This is the default value of [ThemeData.materialTapTargetSize] and the
  /// recommended size to conform to Android accessibility scanner
  /// recommendations.
  padded,

  /// Shrinks the tap target size to the minimum provided by the Material
  /// specification.
  shrinkWrap,
like image 185
awaik Avatar answered Feb 19 '26 10:02

awaik


This is how you can set 45 padding for your elevated button.

ElevatedButton(
      onPressed: () {},
      child: Text('hi'),
      style: ButtonStyle(
        padding: MaterialStateProperty.resolveWith<EdgeInsetsGeometry>(
          (Set<MaterialState> states) {
            return EdgeInsets.all(45);
          },
        ),
      ),
    );
like image 29
Jay Dangar Avatar answered Feb 19 '26 10:02

Jay Dangar