Skip to content

NestedScrollView allows dragging when there is not enough content to scroll #136069

@EArminjon

Description

@EArminjon

Is there an existing issue for this?

Steps to reproduce

  1. Run app
  2. On NestScrollViewPage put your finger in the list and try to scroll up
  3. Go to ListViewPage, put your finger in the list and try to scroll up

Expected results

Scroll should not work thanks of the usage of physics: const ClampingScrollPhysics().

Actual results

In NestScrollViewPage, the list is scrollable despite usage of the physics ClampingScrollPhysics.
NestScrollViewPage should not recognize ClampingScrollPhysics physics.

I reported by the past a similar issue using the physics NeverScrollableScrollPhysics, it is fixed today : #113753.

Code sample

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

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

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

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Builder(builder: (context) {
        return Scaffold(
          bottomNavigationBar: BottomNavigationBar(
            currentIndex: DefaultTabController.of(context).index,
            onTap: (int value) {
              setState(() {
                DefaultTabController.of(context).animateTo(value);
              });
            },
            items: const <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                label: "NestedScrollViewPage",
                icon: Icon(Icons.home),
              ),
              BottomNavigationBarItem(
                label: "ListViewPage",
                icon: Icon(Icons.home),
              ),
            ],
          ),
          backgroundColor: Colors.white,
          body: const TabBarView(
            physics: NeverScrollableScrollPhysics(),
            children: <Widget>[
              NestedScrollViewPage(),
              ListViewPage(),
            ],
          ),
        );
      }),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return ListView(
      physics: const ClampingScrollPhysics(),
      children: <Widget>[
        AppBar(
          title: const Text("Physics working"),
        ),
        for (int index = 0; index < 5; ++index)
          Card(
            child: ListTile(
              onTap: () {},
              leading: const Icon(Icons.search),
              title: Text(index.toString()),
            ),
          ),
      ],
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return NestedScrollView(
      physics: const ClampingScrollPhysics(),
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) => <Widget>[
        const SliverAppBar(
          pinned: false,
          title: Text("Physics not working"),
        ),
      ],
      body: Builder(
        builder: (BuildContext context) => CustomScrollView(
          slivers: <Widget>[
            SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) => Card(
                  child: ListTile(
                    onTap: () {},
                    leading: const Icon(Icons.search),
                    title: Text(index.toString()),
                  ),
                ),
                childCount: 5,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

issue

Logs

No logs

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.13.6, on macOS 13.5.2 22G91 darwin-arm64, locale fr-FR)
    • Flutter version 3.13.6 on channel stable at /Users/earminjon/fvm/versions/3.13.6
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ead455963c (10 days ago), 2023-09-26 18:28:17 -0700
    • Engine revision a794cf2681
    • Dart version 3.1.3
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/earminjon/Library/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/earminjon/Library/Android/Sdk
    • Java binary at: /Users/earminjon/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

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

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/earminjon/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.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.2)
    • IntelliJ at /Users/earminjon/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 75.1.4
    • Dart plugin version 232.9559.10

[✓] VS Code (version 1.76.2)
    • VS Code at /Users/earminjon/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64  • Android 14 (API 34) (emulator)
    • macOS (desktop)             • macos         • darwin-arm64   • macOS 13.5.2 22G91 darwin-arm64
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 117.0.5938.149

[✓] 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: scrollingViewports, list views, slivers, etc.found in release: 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions