Search code examples
flutterdartflutter-layout

Flutter Column with ListView and more Widgets above it


i'm trying a simple title -> search box -> listview thing, but can;t figure out how to fill the screen without tripping the horrible overflow error.

body: Padding(
    padding: const EdgeInsets.all(8.0),
    child: Column(
      children: [
        Text('title', textAlign: TextAlign.center, style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),),
......
TextField(textfield_settings),
SingleChildScrollView(
          child: Container(
            height: MediaQuery.of(context).size.height * 0.6, // the part i want to get rid of and have a flexible height, based on the total screen size and the other widgets
            child: ListView.builder(itemBuilder: (ctx, index) {})
    )
)

I Basically want the SingleChildScrollView containing the ListView.builder to take up the rest of the space left in the body.

thanks!


Solution

  • Use Expanded on ListView

    body: Padding(
      padding: const EdgeInsets.all(8.0),
      child: Column(
        children: [
          Text(
            'title',
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
          ),
          TextField(),
          Expanded(
            child: ListView.builder(
              itemBuilder: (ctx, index) {
                return Text("sds");
              },
            ),
          ),
        ],
      ),
    ),