Uranus_ly
Uranus_ly

Reputation: 151

Flexible Container in flutter

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

Upvotes: 2

Views: 1288

Answers (2)

Sabahat Hussain Qureshi
Sabahat Hussain Qureshi

Reputation: 1364

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

Upvotes: 2

Ivo
Ivo

Reputation: 23337

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

Upvotes: 2

Related Questions