1

I was trying to make an app with SingleChildScrollView and ListView using below code

SingleChildScrollView(
          child: Column(
            children: [
              maintile(),
              Container(
                padding: EdgeInsets.all(15.0),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                    topRight: Radius.circular(75.0),
                  ),
                ),
                child: ListView.builder(
                  shrinkWrap: true,
                  primary: false,
                  itemCount: items.length,
                  itemBuilder: (context, index) {
                    return listitem();
                  },
                ),
              ),
            ],
          ),
        

but the listview holding container does not take available space If I provide Expandable around it. is there any way to achieve Container take available space?

2 Answers2

1

Use Expanded for Container parent like this :

Expanded(
      child: Container(
        child: Text("YOUR_WIDGET"),
      ),
    )
Milad jalali
  • 622
  • 9
  • 10
0

Final Code:

final screenSize = MediaQuery.of(context).size;
return SafeArea(
  child: Scaffold(
      body: Container(
        height: screenSize.height,
        width: screenSize.width,
        child: Column(
          children: [
            maintile(),
            Expanded(
              child: Container(
                padding: EdgeInsets.all(15.0),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                    topRight: Radius.circular(75.0),
                  ),
                ),
                child: ListView.builder(
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                  itemCount: items.length,
                  itemBuilder: (context, index) {
                    return listitem();
                  },
                ),
              ),
            ),
          ],
        ),
      )
  ),
);
Maz341
  • 2,232
  • 15
  • 20
  • if screenSize won't work then remove height : screenSize.height to double.infinity and same for width – Maz341 Oct 08 '20 at 07:31
  • this is not what I want. I want to scroll everything including listview, that's I include SingleChildScrollView – Jacob George Oct 08 '20 at 07:55
  • Then your root would be first SingleChildScrollView then Container – Maz341 Oct 08 '20 at 08:03
  • I mean when I scroll main tile and listview both scrolls, that's why I disabled ListView scrolling. – Jacob George Oct 08 '20 at 08:28
  • Have you tried wrapping the `ListView` inside an `Expanded`? & removing the one around the parent `Container`. That's what I always do to make my ListView fill the space. – mrj Oct 08 '20 at 13:10
  • I want the container, Expanded working only inside of Column/Row? – Jacob George Oct 08 '20 at 14:47