0

I'm getting a renderflex overflow error which displays as the following: overflow

It's coming from the following code:

                  return Column(
                      children: [
                        DropdownButton<String>(
                            items: Utils.ddsDropdown
                                .map<DropdownMenuItem<String>>((String value) {
                              return DropdownMenuItem<String>(
                                value: value,
                                child: Text(value),
                              );
                            }).toList(),
                            onChanged: (value) {}),
                        ListView.builder(
                          shrinkWrap: true,
                          padding: const EdgeInsets.fromLTRB(0, 16, 0, 16),
                          itemCount: card.length,
                          itemBuilder: (context, index) {
                            return MyCard.buildCard(card[index], context);
                          },
                        )
                      ],
                    )

I also tried to wrap the column in an Expanded widget and in a SingleChildScrollView but still got the same error. I think the column is preventing the page from being fully scrollable. But I need the column to be able to have the DropdownButton and ListView.

I even tried wrapping the entire widget in a SingleChildScrollView as follows:

        Widget build(BuildContext context) => SingleChildScrollView(
          child: FutureBuilder<List<Map<String, dynamic>>>(
        future: MyCard.getData(widget.categoryIndex, widget.subCategories)!
            .whenComplete(() => setState(() {
                  isLoading = false;
                })),
        builder: ((context, snapshot) {
          if (snapshot.hasData && snapshot.data!.isNotEmpty) {
            return FutureBuilder<List<MyCard>>(
                future: MyCard.readData(snapshot.data),
                builder: (context, cards) {
                  if (cards.hasData) {
                    final card = cards.data!;
                    return Column(
                      children: [
                        //Text("Hello"),
                        DropdownButton<String>(
                            items: Utils.ddsDropdown
                                .map<DropdownMenuItem<String>>((String value) {
                              return DropdownMenuItem<String>(
                                value: value,
                                child: Text(value),
                              );
                            }).toList(),
                            onChanged: (value) {}),
                        ListView.builder(
                          shrinkWrap: true,
                          padding: const EdgeInsets.fromLTRB(0, 16, 0, 16),
                          itemCount: card.length,
                          itemBuilder: (context, index) {
                            return MyCard.buildCard(card[index], context);
                          },
                        )
                      ],
                    );
                  } else {
                    return const Text("No data");
                  }
                });
          } else {
            return isLoading
                ? Column(
                    children: const [CircularProgressIndicator()],
                  )
                : const Text("You do not have any workouts yet");
          }
        }),
      ));

but it still overflows.

2
  • can you include more about parent widget Commented Jan 20, 2023 at 16:21
  • The issue was the parent widget. The parent widget was a Column, so I changed it to Center Commented Jan 20, 2023 at 17:04

2 Answers 2

0

Wrap only the ListView in Expanded as follows:

Column(
  children: [
    DropdownButton<String>(
    ...
    Expanded(
      child: ListView.builder(
...

This other answer will provide you with further details about your question.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried that and got an error saying that: RenderFlex children have non-zero flex but incoming height constraints are unbounded.
Solved, the problem is that I was wrapping this widget in a Column.
0

Use SingleChildScrollView to use a scrollable area of that column as below:

return SingleChildScrollView(
         child: Column(
                  children: [
                    DropdownButton<String>(
                        items: Utils.ddsDropdown
                            .map<DropdownMenuItem<String>>((String value) {
                          return DropdownMenuItem<String>(
                            value: value,
                            child: Text(value),
                          );
                        }).toList(),
                        onChanged: (value) {}),
                    ListView.builder(
                      shrinkWrap: true,
                      padding: const EdgeInsets.fromLTRB(0, 16, 0, 16),
                      itemCount: card.length,
                      itemBuilder: (context, index) {
                        return MyCard.buildCard(card[index], context);
                      },
                    )
                  ],
                )

I hope this solved your problem.

1 Comment

I tried it but I am still getting a RenderFlex overflow error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.