Skip to content

Scrollable not changing ScrollBehaviour #130793

@Dampfwalze

Description

@Dampfwalze

Is there an existing issue for this?

Steps to reproduce

Create a Scrollable widget and change its scrollBehavior property at runtime (using state or hot reload).

Expected results

Changes to scrollBehavior should be applied without completely recreating the Scrollables state.

Actual results

The observed scroll behavior always stays the same.

Code sample

This version does not work:

class _NotWorkingState extends State<NotWorking> {
  bool _enable = true;

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          body: Scrollable(
            scrollBehavior: const MaterialScrollBehavior().copyWith(dragDevices: {
              if (_enable) PointerDeviceKind.mouse,
            }),
            viewportBuilder: (context, position) => Viewport(
              offset: position,
              slivers: [
                for (int i = 0; i < 100; i++)
                  SliverToBoxAdapter(
                    child: Text("Item $i"),
                  ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(onPressed: () {
            setState(() {
              _enable = !_enable;
            });
          }),
        ),
      );
}

While this one does:

class _WorkingState extends State<Working> {
  bool _enable = true;

  @override
  Widget build(BuildContext context) => MaterialApp(
        scrollBehavior: const MaterialScrollBehavior().copyWith(dragDevices: {
          if (_enable) PointerDeviceKind.mouse,
        }),
        home: Scaffold(
          body: Scrollable(
            viewportBuilder: (context, position) => Viewport(
              offset: position,
              slivers: [
                for (int i = 0; i < 100; i++)
                  SliverToBoxAdapter(
                    child: Text("Item $i"),
                  ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(onPressed: () {
            setState(() {
              _enable = !_enable;
            });
          }),
        ),
      );
}

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.10.6, on Microsoft Windows [Version 10.0.19045.3208], locale de-DE)
    • Flutter version 3.10.6 on channel stable at C:\Users\...\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (6 days ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) 
    • Android SDK at C:\Users\...\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java       
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)     
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Professional 2022 17.6.5) 
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Professional
    • Visual Studio Professional 2022 version 17.6.33829.357
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 11.0.10+0-b96-7249189)

[√] VS Code (version 1.80.1)
    • VS Code at C:\Users\...\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.68.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19045.3208]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 114.0.5735.199
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 114.0.1823.82

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

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.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13frameworkflutter/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

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions