Home > Back-end >  How to use maxWidth in a LayoutBuilder in flutter?
How to use maxWidth in a LayoutBuilder in flutter?

Time:10-12

 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)),
      )),

CodePudding user response:

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

 constrains: BoxConstraints (
       maxWidth: MediaQuery.of(context).size.width*0.5
     ),

CodePudding user response:

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

  • Related