Skip to content

ListWheelScrollView children do not respond on gesture (onTap) events #38803

Closed

Description

@kofan

Steps to Reproduce

Hi! Here is my widget that uses ListWheelScrollView with FixedExtentScrollController:

import 'package:flutter/material.dart';

class LetterWheel extends StatefulWidget {
  const LetterWheel({Key key}) : super(key: key);

  @override
  _LetterWheelState createState() => _LetterWheelState();
}

class _LetterWheelState extends State<LetterWheel> {
  FixedExtentScrollController scrollController;

  @override
  void initState() {
    scrollController = FixedExtentScrollController();
    super.initState();
  }

  @override
  void dispose() {
    scrollController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return ListWheelScrollView(
      controller: scrollController,
      physics: const FixedExtentScrollPhysics(),
      itemExtent: 110,
      children: ['A', 'B', 'C', 'D', 'E', 'F', 'G']
          .map(
            (letter) => Container(
              margin: const EdgeInsets.all(10),
              height: 90,
              color: Colors.yellow,
              child: GestureDetector(
                onTap: () => print('Letter "$letter" is pressed.'),
                child: Center(
                  child: Text(
                    letter,
                    style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                  ),
                ),
              ),
            ),
          )
          .toList(),
    );
  }
}

Expected result: When the list item is tapped the message is printed to the console.

Actual result: When the list item is tapped nothing happens.

Here is my flutter doctor -v output:

[✓] Flutter (Channel stable, v1.7.8+hotfix.3, on Mac OS X 10.14.5 18F203, locale en-UA)
    • Flutter version 1.7.8+hotfix.3 at /Users/mkofan/Software/flutter
    • Framework revision b712a172f9 (6 weeks ago), 2019-07-09 13:14:38 -0700
    • Engine revision 54ad777fd2
    • Dart version 2.4.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
    • Android SDK at /Users/mkofan/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • CocoaPods version 1.7.4

[✓] iOS tools - develop for iOS devices
    • ios-deploy 1.9.4

[!] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.37.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.3.0

[✓] Connected device (1 available)
    • Android SDK built for x86 64 • emulator-5554 • android-x64 • Android 9 (API 28) (emulator)

Activity

  1. kofan commented on Aug 20, 2019

    @kofan
    Author

    Here is a similar unresolved issue on Stackoverflow.

  2. added
    f: scrollingViewports, list views, slivers, etc.
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Sep 4, 2019
  3. spiderion commented on Sep 10, 2019

    @spiderion
  4. spiderion commented on Sep 11, 2019

    @spiderion

    @kofan did you find any solution?

  5. kofan commented on Nov 23, 2019

    @kofan
    Author

    Unfortunately, no. I didn't find a solution. I've abandoned the initial design that was based on ListScrollView and fallen back to a regular ListView 😔

  6. added this to the milestone on Jan 10, 2020
  7. TimG38 commented on Jan 17, 2020

    @TimG38

    A couple reports from:

    And my own testing, example snippet:

        for (var i = 0; i < 30; i++) {
          _myList.add(ListTile(
            enabled: true,
            onTap: () {
              print('hello world$i');
            },
            title: Text('title$i',),
            subtitle: Text('subtitle$i'),
          ));
        }
          ...
        body: ListWheelScrollView(
            controller: _controller, // FixedExtentScrollController
            itemExtent: 30,
            children: _myList,
        ),
    

    That ListTile’s onTap doesn’t respond, no print is seen.

    Even if I wrap a child with GestureDetector, such as:

        _myList.add(GestureDetector(
          onTap: () {
            print('hello world$i');
          },
          child: ListTile(
            enabled: true,
            title: Text('title$i',),
            subtitle: Text('subtitle$i'),
          ),
    

    The GestureDetector’s onTap also doesn’t respond.
    I’ve also tried a Button, same thing with the onPressed.

    But if I replace ListWheelScrollView with ListView, then all is working as expected.

    It seems the only ways to interact with this is through onSelectedItemChanged or the controller’s selectedItem?

  8. charlessfriend commented on Feb 4, 2020

    @charlessfriend
     GestureDetector(
         child: ListWheelScrollView(
              onSelectedItemChanged: (index) => selectedItem = index
         ),
         onTap: () => print('Selection: $selectedItem')
    
  9. TimG38 commented on Feb 5, 2020

    @TimG38
     GestureDetector(
         child: ListWheelScrollView(
              onSelectedItemChanged: (index) => selectedItem = index
         ),
         onTap: () => print('Selection: $selectedItem')
    

    We're looking for tap/touch response on the individual children of the ListWheelScrollView, not on the list itself.

  10. charlessfriend commented on Feb 6, 2020

    @charlessfriend
     GestureDetector(
         child: ListWheelScrollView(
              onSelectedItemChanged: (index) => selectedItem = index
         ),
         onTap: () => print('Selection: $selectedItem')
    

    We're looking for tap/touch response on the individual children of the ListWheelScrollView, not on the list itself.

    As a workaround, you can use that same code and just calculate where the tap occurred. Based on the size of your ListWheelScrollView, you can figure out if the tap is within the child's rect. And you should know which child based on the onSelectedItemChanged. You can also use GlobalKey to get the context of the selected child and get the rect of that child and it's descendants. You can then use callbacks to call child methonds.

    TapUpDetails tapDetails;
        Rect childRect;
        return GestureDetector(
          onTapUp: (t) {
            tapDetails = t;
          },
          onTap: () {
            var thisWidget = context.findRenderObject();
            var childPosition = Rect.fromCenter(
                center: thisWidget.semanticBounds.center,
                width: childRect.width,
                height: childRect.height);
            print('parent tapped: ${tapDetails.localPosition}');
            if (childPosition.contains(tapDetails.localPosition))
              print('child was tapped');
            else
              print('child was not tapped');
          },
          child: ListWheelScrollView.useDelegate(
            physics: FixedExtentScrollPhysics(),
            itemExtent: 200,
            childDelegate: ListWheelChildLoopingListDelegate(
              children: rotatedChildren,
            ),
            onSelectedItemChanged: (index) {
              var childWidget = rotatedChildren[index];
              var childKey = childWidget.key as GlobalKey;
              childRect = childKey.currentContext.findRenderObject().semanticBounds;
              print('parent bounds: ${context.findRenderObject().semanticBounds}');
              print('child bounds: $childRect');
    
  11. Moatasem1994 commented on Feb 24, 2020

    @Moatasem1994
  12. rostopira commented on Feb 24, 2020

    @rostopira
  13. sgehrman commented on Mar 27, 2020

    @sgehrman
  14. Stuazt commented on Apr 13, 2020

    @Stuazt
  15. 50 remaining items

  16. Cilestal commented on Jan 19, 2021

    @Cilestal

    For ListWheelScrollView with a fixed height for child, you can use https://pub.dev/packages/clickable_list_wheel_view

  17. mjlorenzo commented on Jan 27, 2021

    @mjlorenzo

    Google,

    I understand ListWheelScrollView children not receiving input gestures is a fairly reasonable design decision. On the other hand, not making this crystal clear in your documentation is obnoxious. It stands to reason items in this list widget would behave identically to a standard list views unless otherwise specified. I wasted three hours today trying to figure out where I was going wrong because this behavior is completely ignored by the official API reference. I may waste more changing course completely. One sentence on the class reference page would do wonders.

  18. medst commented on Jul 9, 2021

    @medst
  19. AzadCoder commented on Oct 25, 2021

    @AzadCoder
  20. Cilestal commented on Nov 6, 2021

    @Cilestal

    Guys any solution after 3 years?

    https://pub.dev/packages/clickable_list_wheel_view

  21. banzhuan-jing commented on Jan 6, 2023

    @banzhuan-jing
  22. Terranic commented on Jan 14, 2023

    @Terranic
  23. LkyYuen commented on Feb 2, 2023

    @LkyYuen
  24. anypwx commented on Feb 23, 2023

    @anypwx
  25. self-assigned this
    on Feb 23, 2023
  26. anypwx commented on Feb 23, 2023

    @anypwx
  27. github-actions commented on Apr 13, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  28. locked as resolved and limited conversation to collaborators on Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projectcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.f: gesturesflutter/packages/flutter/gestures repository.f: scrollingViewports, list views, slivers, etc.found in release: 1.18Occurs in 1.18found in release: 1.24Found to occur in 1.24frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions