0

I'm trying to make the question simple. I need to make a Drawer, It gives me below error:

RenderFlex children have non-zero flex but incoming height constraints are unbounded

I want the drawer to have 3 sections:

|--------------------------------|
|                                |
|           DrawerHeader         |
|                                |
|--------------------------------|
|--------------------------------|
|                                |
|         Scrollable Area        |
|                                |
|           ListItem1            |
|           ListItem2            |
|           ListItem3            |
|                                |
|                                |
|--------------------------------|
|--------------------------------|
|                                |
|        Copyright Section       |
|                                |
|--------------------------------|
Drawer(
  child : Column(
      children: [
        DrawerHeader(
          padding: const ..,
          child: ....,
        ),//DrawerHeader
        Expanded(
          child: ListView(
            children: const [
              ListTile(
                leading: ...,
                title: ...,
              ),//ListTile
              ExpansionTile(
                title: ...,
                children: <Widget>[
                  ListTile(
                    leading: ...,
                    title: ...,
                  ),//ListTile
                  ListTile(
                    leading: ...,
                    title: ...,
                  ),//ListTile
                  ...
                ], //<Widget>
              ),//ExpansionTile
              
              Divider(thickness: 1),
              
            ],//children
          ),//ListView
        ),//Expanded
        const SizedBox(height: kSpacing * 2),
        const Text("Copyright. All Rights Reserved"),
        const SizedBox(height: kSpacing),
      ],//children
    ),//Column
);//Drawer

I've tried more that 8 solution that came up from 4 days searching. here are some examples

Solution 1:

Error

Failed assertion: line 2817 pos 12: '!_needsLayout'

Solution 2:

Error

Failed assertion: line 1979 pos 12: 'hasSize'

Solution 3:

Error

RenderFlex children have non-zero flex but incoming height constraints are unbounded

And tried removing Expanded, use SingleChildScrollView but still doesn't work for me

Poula Adel
  • 609
  • 1
  • 10
  • 33

3 Answers3

1

Add a SizedBox of specific height to give bound for the column that will define a bound for the expanded widget too

Drawer(
  child : SizedBox(//<---here
  height: MediaQuery.of(context).size.height,
  width: MediaQuery.of(context).size.width*0.5,
   child : Column(
      children: [
        DrawerHeader(
          padding: const ..,
          child: ....,
        ),//DrawerHeader
        Expanded(
          child: ListView(
            children: const [
              ListTile(
                leading: ...,
                title: ...,
              ),//ListTile
              ExpansionTile(
                title: ...,
                children: <Widget>[
                  ListTile(
                    leading: ...,
                    title: ...,
                  ),//ListTile
                  ListTile(
                    leading: ...,
                    title: ...,
                  ),//ListTile
                  ...
                ], //<Widget>
              ),//ExpansionTile
              
              Divider(thickness: 1),
              
            ],//children
          ),//ListView
        ),//Expanded
        const SizedBox(height: kSpacing * 2),
        const Text("Copyright. All Rights Reserved"),
        const SizedBox(height: kSpacing),
      ],//children
    ),//Column
  ),//SizedBox
);//Drawer
Kaushik Chandru
  • 15,510
  • 2
  • 12
  • 30
0

Try this it's working well https://prnt.sc/JX49BJc8dyvL

Drawer(
    child : Column(
      children: [
        DrawerHeader(
          child: Container(color: Colors.black),
        ),//DrawerHeader
        Expanded(
            child: ListView(
              children: [
                ListTile(
                    leading: CircleAvatar(
                      backgroundColor: Colors.red,
                    ),
                    title: Text('Red')),
                ExpansionTile(
                  title: Text(
                    "items.playerName",
                    style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w500),
                  ),
                  children: <Widget>[
                    ListTile(
                      title: Text(
                        "items.description",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    ),
                    ListTile(
                      title: Text(
                        "items.description",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    ),
                    ListTile(
                      title: Text(
                        "items.description",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    ),
                    ListTile(
                      title: Text(
                        "items.description",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    ),
                    ListTile(
                      title: Text(
                        "items.description",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    ),
                    ListTile(
                      title: Text(
                        "items.description",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    ),
                    ListTile(
                      title: Text(
                        "items.description",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    ),
                    ListTile(
                      title: Text(
                        "items.description",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    ),
                    ListTile(
                      title: Text(
                        "items.description",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    )
                  ],
                ),
                Divider(thickness: 1),
              ],)),
        const SizedBox(height: 10 * 2),
        const Text("Copyright. All Rights Reserved"),
        const SizedBox(height: 10),
      ],//children
    ),//Column
  ),
Jasmin Sojitra
  • 1,090
  • 10
  • 24
0

after a lot of search and trying different structures. Probably you are using desktop flutter as me.

this Link offers a simple solution when it comes to error

scrollcontroller attached to multiple scroll views

when you use the structre Drawer -> Expanded -> ListView -> ExpansionTile

Explaination:

It happens because of how ScrollViews treat default (null) primary on them. It defaults to true if direction is vertical and there is no scroll controller. Because of that, all your vertical scroll views' scrollbars attach to the PrimaryScrollController, and that is why this error occurs

Solution:

mark appropriate ScrollViews with primary: false, so that you are left with no more than one primary ScrollView

Poula Adel
  • 609
  • 1
  • 10
  • 33