Skip to content

Regression: Incorrect hit-testing when adding SliverPadding(bottom) inside SliverMainAxisGroup on Flutter 3.32.4-stable #171121

@hukusuke1007

Description

@hukusuke1007

Steps to reproduce

  1. Create a CustomScrollView with reverse: true and a SliverMainAxisGroup inside.
  2. Add a SliverPadding(padding: EdgeInsets.only(bottom: 56)) before the SliverGrid.
  3. Build and run on Flutter 3.32.4-stable.
  4. Tap any item inside the SliverGrid.

Expected results

The tapped grid tile should receive the tap event and update its color (or perform any other intended action) exactly under the finger.

Removing the SliverPadding (or placing it outside the SliverMainAxisGroup) fixes the issue.
Using the same widget tree on Flutter 3.29.3 does not reproduce the problem, so this appears to be a regression introduced after that release.

Actual results

The visual tile under the finger is not the one that receives the tap event.
The hit-test region seems to be shifted when a SliverPadding with bottom padding is present inside a SliverMainAxisGroup.

Code sample

https://github.com/hukusuke1007/flutter_sample

Code sample
class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final ScrollController _scrollController = ScrollController();
  int? _selectedIndex;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        reverse: true,
        controller: _scrollController,
        slivers: [
          // Problematic padding ─ removing this line makes taps work again.
          SliverPadding(padding: const EdgeInsets.only(bottom: 56)),

          SliverMainAxisGroup(
            slivers: [
              SliverGrid(
                delegate: SliverChildBuilderDelegate(
                  (context, index) {
                    final selected = _selectedIndex == index;
                    return GestureDetector(
                      behavior: HitTestBehavior.opaque,
                      onTap: () => setState(() => _selectedIndex = index),
                      child: ColoredBox(
                        color: selected
                            ? Theme.of(context).colorScheme.primaryContainer
                            : Colors.transparent,
                        child: Center(child: Text('Item $index')),
                      ),
                    );
                  },
                  childCount: 100,
                ),
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 4,
                  mainAxisSpacing: 1,
                  crossAxisSpacing: 1,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.32.4, on macOS 15.5 24F74 darwin-arm64, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.3)
[✓] VS Code (version 1.101.1)
[✓] Connected device (4 available)
[✓] Network resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listc: regressionIt was better in the past than it is nowf: 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 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