Flutter ListView not scrolling when CustomCard wrapper by GestureDetector

Issue

I have a ListView to display a list of Cards. When user clicks on card, the Details Page is called. To recognize the Tap gesture, I wrapped the CustomCard with the GestureDetector, but after this the List is not scrolling anymore.

class PageUI extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              SizedBox(height: 48),
              Text(
                'PageTitle',
                style: Get.theme.textTheme.headline5,
              ),
              SizedBox(height: 18),
              ListView.builder(
                  scrollDirection: Axis.vertical,
                  shrinkWrap: true,
                  itemCount: list.length,
                  itemBuilder: (context, index) => GestureDetector(
                    child: CustomCard(item: list[index]),
                    onTap: () {
                      // Navigate to DetailsPage
                    },
                  ),
                ),
            ],
          ),
        ),
    );
  }
}

Solution

Please try

ListView.builder(
              scrollDirection: Axis.vertical,
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemCount: 10,
              itemBuilder: (context, index) => GestureDetector(
                child: CustomCard(item: list[index]),
                onTap: () {
                  // Navigate to DetailsPage
                },
              ),
            ),

Answered By – Jahidul Islam

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *