Skip to content

Scrollable widget has an opaque hitTestBehavior and won't give widgets under it a chance to catch hits #146401

@Amir-P

Description

@Amir-P

Steps to reproduce

  1. Run the sample app
  2. Tap on a red widget
  3. Tap on a green widget

Expected results

Both red and green widget should catch the tap and you should get these logs in console:

flutter: onTap 1
flutter: onTap 2

Actual results

Only green widgets receive the tap since they're caught by the topmost Scrollable:

flutter: onTap 2

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(home: Home()));
}

class Home extends StatelessWidget {
  const Home({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          ListView.builder(
            itemBuilder: (c, i) {
              final child = Container(
                height: 100,
                color: i.isEven ? Colors.red : null,
                child: Text('$i'),
              );
              if (i.isEven) {
                return GestureDetector(
                  onTap: () => print('onTap 1'),
                  child: child,
                );
              }
              return child;
            },
          ),
          ListView.builder(
            itemBuilder: (c, i) {
              final child = Container(
                height: 100,
                color: i.isOdd ? Colors.green : null,
                child: Text('$i'),
              );
              if (i.isOdd) {
                return GestureDetector(
                  onTap: () => print('onTap 2'),
                  child: child,
                );
              }
              return child;
            },
          ),
        ],
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.4.1 23E224 darwin-arm64, locale
    en-US)
    • Flutter version 3.19.3 on channel stable at /Users/amirpanahandeh/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (4 weeks ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/amirpanahandeh/SDK
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/amirpanahandeh/SDK
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)

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

[✓] Connected device (4 available)
    • Amir’s iPhone (mobile)     • 00008101-00052C14362A001E            • ios
      • iOS 17.4.1 21E236
    • iPhone 15 Pro Max (mobile) • 152C5F7B-B91F-4787-A67F-54A919478013 • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator)
    • macOS (desktop)            • macos                                •
      darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
    • Chrome (web)               • chrome                               •
      web-javascript • Google Chrome 119.0.6045.123

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: gesturesflutter/packages/flutter/gestures repository.f: scrollingViewports, list views, slivers, etc.found in release: 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework teamwaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions