Home > database >  The argument type 'EdgeInsets' can't be assigned to the parameter type 'Material
The argument type 'EdgeInsets' can't be assigned to the parameter type 'Material

Time:12-08

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

CodePudding user response:

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.

  • Related