0

I want to build a scrollable widget that consists of some Text widgets (and maybe some other widgets) that are produced by a function. However, I'm getting the following error:

A RenderFlex overflowed by 701 pixels on the bottom.

I'm not sure what the best layout is here. Should the scrollable Column be placed outside the container? Is a Column at the innermost nesting required? Is another Expanded widget required?

Also, the Text inside the widget list should be aligned left, not centereed. If someone could help with a useful solution, I'd be very thankful!

Here's my current code:

List<Widget> getWidgetList(){
// do some stuff and return a list
return [Text("foo"), Text("bar")];
}

@override
Widget build(BuildContext context) => Scaffold(... body:
      Container(
          padding: EdgeInsets.all(20),
          child:
          SingleChildScrollView(
              scrollDirection: Axis.vertical,
              child:
              SizedBox(
                  height: MediaQuery.of(context).size.height,
                  child:
                  Column(
                      children: getWidgetList()
                  )
              )
          )
      )
    );
}

1 Answer 1

2

I think the overflow happens from getWidgetList. Remove the fixed height from SizedBox,

You can use ListView, it provide padding params,

ListView(
  padding: EdgeInsets.all(20),
  children: [
    ...getWidgetList(),
  ],
),

Old

   Container(
          padding: EdgeInsets.all(20),
          child:
          SingleChildScrollView(
              scrollDirection: Axis.vertical,
              child:
              SizedBox(
                 // height: MediaQuery.of(context).size.height,
                  child:
                  Column(
                      children: getWidgetList()
                  )
              )
          )
      )
    );
Sign up to request clarification or add additional context in comments.

16 Comments

so the SizedBox is to be removed too and in this case the whole code could be reduced to single ListView(children: getWidgetList())
you will get 0.01 ms maybe, yes Padding is better but you will not notice that
all of them use slivers: CustomScrollView code
Mint LDME 4 Debbie - yes 4GB but I am using vscode since the newest android studio becomes too slow now
also children:[...getWidgetList(),], is not needed children: getWidgetList(), is enough as getWidgetList() returns a List
|

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.