2

I was working on this simple app and I can't seem to change the width and height properties of a raised button, I also tried using a flat button but it doesn't work either.Here's a screenshot

Row (mainAxisAlignment: MainAxisAlignment.spaceEvenly,
           children: <Widget>[
             RaisedButton(
               height: 20,
               color: Colors.green,
               onPressed: () {
                 setState(() { });
               },

Error message: The named parameter 'height' isn't defined. Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'height'.

2
  • Please include formatted code in the body of your question. You can format code blocks using three backticks (`) or tildes (~) on the lines before and after your code. More formatting help here. Error messages should also be included in the body of your post. Commented Sep 27, 2020 at 21:27
  • I have formatted it Commented Sep 27, 2020 at 21:36

2 Answers 2

1

You should wrap your Raised Button with other widget that pass his contraints, like Container

Container(
  width: 200,
  height: 50,
  child: RaisedButton(
    onPressed: this.action,
    color: Colors.blue,
    child: Text('Title', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
  ),
)
Sign up to request clarification or add additional context in comments.

2 Comments

Isn't the button supposed to have a height property by itself?
RaisedButton does not have a property to set its size by itself. It can inherit constraints from a parent
0

As you can see in the link raisedButton doc

You need to wrap the button widget with button theme widget after that you are ready to go. I put a example code:

ButtonTheme(
  minWidth: 200.0,
  height: 100.0,
  child: RaisedButton(
    onPressed: () {},
    child: Text("test"),
  ),
);

3 Comments

but why though according to the flutter documentation it should have properties like height and minWidth.
if you check Constructors there is not a properties like height and minWidth. They are under the Properties headline and the button has the properties but to set that you need to use another widget.
but it is listed under properties, I'm getting really confused

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.