Search code examples
androidiosflutterflutter-animation

How do I disable scrolling for ListView.builder and at the same time let the whole page scroll


I'm creating a page which contains a section built through a listview.builder (inside a future builder), now If I let the whole page scroll by wrapping the parent Container with single child scrollview and disable the scrolling physics of listview it doesn't scroll to the end of the lists. if I enable the scrolling of listview,it doesn't bring any change except that the listview is scrollable separately

Here is my code

Scaffold(
      body: SingleChildScrollView(
        child: Container(
          height: size.height,
          margin: const EdgeInsets.symmetric(horizontal: 25),
          decoration: BoxDecoration(
              color: isLight ? lightBeigeColor : lightGreyColor,
            border: Border.symmetric(vertical: BorderSide(color: blueColor,width: 2))
              ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              //a number of children widgets
              Expanded(
                child: FutureBuilder<List<Posts>>(
                    //fetching data + error handeling code
                        return ListView.builder(
                              //technical code
                              itemBuilder: (context, index) {
                              return Container(
                                margin: const EdgeInsets.symmetric(
                                    vertical: 20,horizontal: 10),
                                padding: const EdgeInsets.all(10),
                                height: size.height / 2.8,
                                decoration: BoxDecoration(
                                    color:isLight ? lightBeigeColor : lightGreyColor,
                                  borderRadius: BorderRadius.circular(10),
                                  border: Border.all(
                                    color: blueColor,
                                    width: 1.5
                                  )
                                ),
                                child: Column(
                                  //some widgets in here
                                  ),
                              );
                            }
                           );
                      }
                    }),
              ),
            ],
          ),
        ),
      ),
    );

Solution

  • You don't need to use ListView if the parent widget is already handling scrolling. You can use Column widget.

    builder: (context, snapshot) {
     return Column(
       children: snapshot.data?.map((e) {
         return Container();
       },).toList()?? [],
     );
    },
    

    A better approach will be using CustomScrollView.