Skip to content

SliverMainAxisGroup breaks GestureDetector details when slivers are partially off screen #173029

@wreppun

Description

@wreppun

Steps to reproduce

  1. Create a CustomScrollView with a SliverMainAxisGroup
  2. Add some child slivers that contain GestureDetector
  3. Tap on the upper left corner of a child that's partially off screen
  4. Check the details of the onTapDown callback

Expected results

The details.localPosition in the top left corner should be relatively close to Offset(0, 0) (depending on how close you can tap/click).

Actual results

The details.localPosition is not close to Offset(0, 0).

In the example below, when a box is just slightly on-screen, tapping the top left corner gives ~Offset(0, 600)

Notes:

  • Tested on iOS and Web
  • Only checked onTapDown

Code sample

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

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(title),
      ),
      body: CustomScrollView(
        slivers: [
          SliverMainAxisGroup(
            slivers: [
              SliverToBoxAdapter(
                child: GestureDetector(
                  onTapDown: (details) {
                    // Details will be wrong if child is partially off screen
                    print('[green] ${details.localPosition}');
                  },
                  child: SizedBox(
                    height: 600,
                    width: 300,
                    child: Container(
                      color: Colors.green.shade100,
                    ),
                  ),
                ),
              ),
              SliverToBoxAdapter(
                child: GestureDetector(
                  onTapDown: (details) {
                    // Details will be wrong if child is partially off screen
                    print('[orange] ${details.localPosition}');
                  },
                  child: SizedBox(
                    height: 600,
                    width: 300,
                    child: Container(
                      color: Colors.orange.shade100,
                    ),
                  ),
                ),
              )
            ],
          ),
          // NOT wrapped in a SliverMainAxisGroup
          SliverToBoxAdapter(
            child: GestureDetector(
              onTapDown: (details) {
                // Details will be correct, since this is _not_ wrapped in a
                // SliverMainAxisGroup.
                print('[purple] ${details.localPosition}');
              },
              child: SizedBox(
                height: 600,
                width: 300,
                child: Container(
                  color: Colors.purple.shade100,
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}

Screenshots or Video

No response

Logs

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.33.0-1.0.pre-1202, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 15.4)
    ✗ CocoaPods installed but not working.
        You appear to have CocoaPods installed but it is not working.
        This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
        This can usually be fixed by re-installing CocoaPods.
      For re-installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation
[✓] Chrome - develop for the web
[✓] Connected device (3 available)
[✓] Network resources

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: gesturesflutter/packages/flutter/gestures repository.f: material designflutter/packages/flutter/material repository.f: scrollingViewports, list views, slivers, etc.found in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33frameworkflutter/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 team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions