How to use maxWidth in a LayoutBuilder in flutter?

678 Views Asked by At
 LayoutBuilder(
  builder: (context, constraints) => Container(
        width: constraints.maxWidth =
            0.5, //this is where maxWidth is being is used and it is just giving an error

        decoration: BoxDecoration(
            gradient: kPrimaryGradient,
            borderRadius: BorderRadius.circular(50)),
      )),
2

There are 2 best solutions below

0
Nijat Namazzade On

You can use containers with constrains to achieve this layout. For example.

 constrains: BoxConstraints (
       maxWidth: MediaQuery.of(context).size.width*0.5
     ),
0
Md. Yeasin Sheikh On

The LayoutBuilder's constraints controlled by its parent widget. If you like to have 50% width of the constraints use

width: constraints.maxWidth *.5

The operation will * instead of =.

You can find more about dart