0

How do I deal with using multiple unit types (percentage of space, number of pixels, etc.) to size a widget? A CSS equivalent example is div{width: 70%; height: 50px}

Bill--
  • 140
  • 3
  • 6

1 Answers1

0

Could do something like this:

        Container(
          width: MediaQuery.of(context).size.width * 0.50, // this would be 50% of screen width
          height: 50,
        )

Another option would be:

        LayoutBuilder(
            builder: (BuildContext context, BoxConstraints constraints) {
                return Container(
                  width: constraints.maxWidth * 0.50, // 50% of parent size
                  height: 50,
                );
            }
        )

More info at: Sizing elements to percentage of screen width/height

Adelina
  • 10,915
  • 1
  • 38
  • 46