Flutter: How to make a button expand to the size of its parent?

前端 未结 2 1486
情歌与酒
情歌与酒 2021-02-11 14:29

I am trying to create square buttons, but Expanded doesn\'t seem to work the same as it does with containers. Take the following code for example

new Expanded(
          


        
2条回答
  •  走了就别回头了
    2021-02-11 15:10

    Wrapping with a ButtonTheme with minWidth: double.infinity allows to provide constraints

    ButtonTheme(
      minWidth: double.infinity,
      child: MaterialButton(
        onPressed: () {},
        child: Text('Raised Button'),
      ),
    ),
    

    or after https://github.com/flutter/flutter/pull/19416 landed

      MaterialButton(
        onPressed: () {},
        child: SizedBox.expand(
          width: double.infinity, 
          child: Text('Raised Button'),
        ),
      ),
    

提交回复
热议问题