'The argument type 'EdgeInsets' can't be assigned to the parameter type 'MaterialStateProperty<EdgeInsetsGeometry?>?'

I am trying to add some padding to my widget but i am encountering this problem:

TextButton(
  style: ButtonStyle(
    padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 60.0),
  ),
  onPressed: () {}, child: const Text('Text'),
),

enter image description here



Solution 1:[1]

Using MaterialStateProperty allows you to pass a value that can depend on the state of a material widget (usually a MaterialState).

As an example this can prove useful when a button needs to change its color or size when it is being pressed.

In your case using MaterialStateProperty.all as bellow should fix it.

TextButton(
  style: ButtonStyle(
    padding: MaterialStateProperty.all(
      EdgeInsets.symmetric(vertical: 20.0, horizontal: 60.0),
    ),
  ),
  onPressed: () {}, child: const Text('Text'),
),

Its also worth mentioning this similar question.

Edit: relevant video from the flutter channel

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1