Repository navigation
Scrollable not changing ScrollBehaviour #130793
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13Found to occur in 3.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
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.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13Found to occur in 3.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Activity
Dampfwalze commentedon Jul 18, 2023
I did some research myself and concluded, that this is caused by these lines in
ScrollableState.didUpdateWidget:flutter/packages/flutter/lib/src/widgets/scrollable.dart
Lines 666 to 668 in beb245c
because
ScrollableState._shouldUpdatePositiondoes not handle changes toScrollable.scrollBehaviorcorrectly. But due to:flutter/packages/flutter/lib/src/widgets/scrollable.dart
Line 571 in beb245c
it works fine when
Scrollable.scrollBehaviorisnull, since in this caseScollableState.didChangeDependencieswill be called, whenScrollConfigurationchanges, in which,ScrollableState._updatePositionwill be called regardless:flutter/packages/flutter/lib/src/widgets/scrollable.dart
Lines 619 to 624 in beb245c
I found that
ScrollBehaviorhas this convenientbool shouldNotify(covariant ScrollBehavior oldDelegate)method, which maybe can be used to improveScrollableState._shouldUpdatePosition.huycozy commentedon Jul 19, 2023
Thanks for your detailed report. I also can see the issue on master channel with behavior as descibed.
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.0.1 22A400 darwin-x64, locale en-VN) • Flutter version 3.10.6 on channel stable at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f468f3366c (5 hours ago), 2023-07-12 15:19:05 -0700 • Engine revision cdbeda788a • Dart version 3.0.6 • DevTools version 2.23.1 [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-33, build-tools 32.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E222b • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.2) • 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.6+0-17.0.6b802.4-9586694) [✓] VS Code (version 1.80.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.68.0 [✓] Connected device (3 available) • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 13.0.1 22A400 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 114.0.5735.198 [✓] Network resources • All expected network resources are available. • No issues found!Update `Scrollable` on `ScrollBehaviour` change. (#131164)
github-actions commentedon Sep 1, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.