Home > Back-end >  Flexible Container in flutter
Flexible Container in flutter

Time:08-24

I'm making Container box with Flexible funtion but it doesn't work flexible rate (3:7). Could you explain why it doesn't work?

Codes are below.

body: Container(
      child: Row(
        children: [
          Flexible(child: Container(
            color: Colors.lightGreenAccent,
            child: Text("Hi, Lynn",
              style: TextStyle(fontSize: 30),
            ),
          ), flex: 3,),
          Flexible(child: Container(
            color: Colors.blue,
            child: const MyStatefulWidget()
          ), flex: 7,)
        ],
      ),
    )

CodePudding user response:

When you use Flexible it still makes children smaller than the flex when there is enough space. I believe you want to use Expanded. Try replacing it with that

CodePudding user response:

You can use Expanded widget instead of Flexible

Container(
  child: Row(
    children: [
      Expanded(
        child: Container(
          color: Colors.lightGreenAccent,
          child: Text("Hi, Lynn", style: TextStyle(fontSize: 30),),
        ), 
        flex: 3,
      ),
      Expanded(
        child: Container(
          color: Colors.blue,
          child: Text("Hi, Lynn",style: TextStyle(fontSize: 30),)
        ), 
        flex: 7,
      )
    ],
  ),
)
  • Related