How to set the width of a RaisedButton in Flutter?

后端 未结 20 2171
傲寒
傲寒 2021-01-30 06:01

I have seen that I can\'t set the width of a RaisedButton in Flutter. If I have well understood, I should put the RaisedButton into a SizedBox

20条回答
  •  半阙折子戏
    2021-01-30 06:37

    This piece of code will help you better solve your problem, as we cannot specify width directly to the RaisedButton, we can specify the width to it's child

    double width = MediaQuery.of(context).size.width;
    var maxWidthChild = SizedBox(
                width: width,
                child: Text(
                  StringConfig.acceptButton,
                  textAlign: TextAlign.center,
                ));
    
    RaisedButton(
            child: maxWidthChild,
            onPressed: (){},
            color: Colors.white,
        );
    

提交回复
热议问题