Search code snippets, questions, articles...

Set height and width of Button in Flutter

If you're creating a button in Flutter, you may want to know how to set the height and width. This can be done in a few different ways, and we'll cover them here. First, you can use the SizedBox widget to set specific dimensions, or you can use the ConstrainedBox widget to set constraints on the button's size.

Set height and width of Button in Flutter

In order to apply height and width to a Button Widget in flutter:

  1. Create a SizedBox widget and assign height and width to it.
  2. Add the Button widget as its child and the button will take the height and width of the SizedBox widget.

Using SizedBox Widget

If you want to set the height and width of a button in Flutter, you can use the SizedBox widget. The SizedBox widget allows you to set a specific size for a widget. Here, we will learn how to use the SizedBox widget to set the height and width of a button in Flutter.

SizedBox(
  width: 250,
  height: 50,
  child: OutlinedButton(
    onPressed: () {
      print("hello world");
    },
    child: const Text("English", style: ThemeText.btnA),
  ),
),

The above code creates a button that is 250px wide and 50px tall. When the button is pressed, it will print "hello world" to the console.


Was this helpful?
0 Comments