How to make button width match parent?


With Flutter 2.0 RaisedButton is deprecated and replaced by ElevatedButton. you can use minimumSize like this:

  style: ElevatedButton.styleFrom(
    minimumSize: Size.fromHeight(40), // fromHeight use double.infinity as width and 40 is the height
  onPressed: () {},
  child: Text('Text Of Button'),

Old answer for Flutter less than 2.0:

The correct solution would be to use the SizedBox.expand widget, which enforces its child to match its parent’s size.

  child: RaisedButton(...),

There are many alternatives, which allows for more or less customization:

  width: double.infinity,
  // height: double.infinity,
  child: RaisedButton(...),

or using a ConstrainedBox

  constraints: const BoxConstraints(minWidth: double.infinity),
  child: RaisedButton(...),

Leave a Comment