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

前端 未结 2 1488
情歌与酒
情歌与酒 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:07

    Add the crossAxisAlignment property to your Row;

    crossAxisAlignment: CrossAxisAlignment.stretch
    
    0 讨论(0)
  • 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'),
        ),
      ),
    
    0 讨论(0)
提交回复
热议问题