Bruno Neuman
Bruno Neuman

Reputation: 148

Flutter ListView not scrolling when CustomCard wrapper by GestureDetector

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
                    },
                  ),
                ),
            ],
          ),
        ),
    );
  }
}

Upvotes: 0

Views: 581

Answers (1)

Jahidul Islam
Jahidul Islam

Reputation: 12575

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
                },
              ),
            ),

Upvotes: 4

Related Questions