skip to Main Content
class _CalculatorState extends State<Calculator> {
  Widget calcbutton(String btntxt, Color btncolor, Color txtcolor) {
    return Container(
      child: RaisedButton(
        onPressed: () {
          calculation(btntxt);
        },
        child: Text(
          btntxt,
          style: TextStyle(
            fontSize: 35,
            color: txtcolor,
          ),
        ),
        shape: CircleBorder(),
        Color: btncolor,
        padding: EdgeInsets.all(20),
      ),
    );
  }

When changing the Raised Button to ElevatedButton, errors on shape, Color, padding immediately appear

2

Answers


  1. To have elevated button with the shape, color, and padding options available, use MaterialButton. You can set elevation for various state of the button.

    MaterialButton(
      onPressed: () {
        calculation(btntxt);
      },
      child: Text(
        btntxt,
        style: TextStyle(
          fontSize: 35,
          color: txtcolor,
        ),
      ), 
      shape: CircleBorder(),
      color: btncolor,
      padding: EdgeInsets.all(20),
      // set elevation options below
      elevation: 2,
      focusElevation: 4,
      hoverElevation: 4,
      highlightElevation: 8,
      disabledElevation: 0,
    ),
    
    Login or Signup to reply.
  2. With the new ElevatedButton, these settings are now in the style property.
    In your case, this example should do it.
    You can set other properties inside Elevatedbutton.styleFrom

    return ElevatedButton(
      style: ElevatedButton.styleFrom(
        padding: const EdgeInsets.all(20),
        backgroundColor: Colors.red,
        shape: const CircleBorder(),
      ),
      onPressed: () {},
      child: const Text(
        btntxt,
        style: TextStyle(
          fontSize: 35,
          color: txtcolor,
        ),
      ),
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search