Repository navigation
Combining NestedScrollView with TabBarView has problems. #81619
Description
Hi! My post is related to this one.
So
1)If I use AutomaticKeepAliveMixin to keep the inner scrollers (and each of their children built by builder: methods), they are kept alive and when changing between the tabs, there are no lags in animation.
However, any scrolling of one of the inner scrollers also affects others and the individual scroll positions are not obeyed. Even though I use different PageStorageKey() for all of the scrollers, if AutomaticKeepAliveMixin is applied, scroll positions are problematic.
You can see this behavior here
2)If I don't apply AutomaticKeepAliveMixin to the inner scrollers, scroll positions have no issues and work as expected. However, this time, because each of the inner scrollers (and their respective children) is completely rebuilt whenever a tab change occurs.
When there are relatively fewer items inside inner scrollers (like 20-30 items per tab), TabBarView tab change animations are fluid and no issues. However, when after a user scrolls and fills lots of children into inner scrollers, then tab change becomes very laggy. This happens because the inner scrollers build from scratch.
You can see this behavior here
flutter doctor -v
[√] Flutter (Channel stable, 2.0.5, on Microsoft Windows [Version 10.0.18363.1500], locale en-US)
• Flutter version 2.0.5 at C:\src\flutter
• Framework revision adc687823a (2 weeks ago), 2021-04-16 09:40:20 -0700
• Engine revision b09f014e96
• Dart version 2.12.3
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc2)
• Android SDK at C:\Users\Teq\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.0-rc2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.1.0)
• 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 1.8.0_242-release-1644-b01)
[√] IntelliJ IDEA Ultimate Edition (version 2020.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2020.1
• Flutter plugin version 45.1.3
• Dart plugin version 201.7223.43
[√] VS Code, 64-bit edition (version 1.55.2)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.21.0
[√] Connected device (4 available)
• Android SDK built for x86 64 (mobile) • emulator-5554 • android-x64 • Android 10 (API 29) (emulator)
• sdk gphone x86 64 arm64 (mobile) • emulator-5560 • android-x64 • Android 11 (API 30) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 90.0.4430.85
• Edge (web) • edge • web-javascript • Microsoft Edge 89.0.774.77
• No issues found!
Activity
TahaTesser commentedon May 3, 2021
Hi @smakarov
Thanks for the detailed explanation of the issue and code samples, I can confirm both problems
1. Inner scroller scroll Issue
code sample
Preview
1. Inner scroller rebuild Issue
code sample
Preview
flutter doctor -v
Patrick386 commentedon Aug 4, 2021
Flutter Web:
Using ExpansionPanelList gives me an error.
aitsuki commentedon Aug 13, 2021
have any workaround?
Patrick386 commentedon Aug 14, 2021
Not resolved yet.
Patrick386 commentedon Aug 17, 2021
I looked into this issue a bit more today, and I fixed it.
Simply just use a SingleChildScrollView at the root of body:
DFelten commentedon Nov 8, 2021
Same issue here. With the official example code from the NestedScrollView there is a bug. Both tabs can be scrolled down individually and keep their position. However, as soon as you scroll up again, the second tab loses its position and starts at the top again.
You can see the behavior in this video:
Simulator.Screen.Recording.-.iPhone.13.-.2021-11-08.at.22.08.51.mp4
Is there maybe a workaround? Currently it's working when removing floating from the SliverAppBar:
Simulator.Screen.Recording.-.iPhone.13.-.2021-11-08.at.22.12.11.mp4
Code from the example:
smakarov commentedon Nov 9, 2021
@DFelten I'm using extended_nested_scroll_view package for fix.
6 remaining items
techouse commentedon Sep 13, 2022
For anyone still looking for an answer, check out extended_nested_scroll_view. It fixed all my problems.
akbulutdora commentedon Sep 14, 2022
How did you handle infinite scroll, pull-to-refresh, and other scrolling actions (that require ScrollController)? Flutter candies seem to have their own packages but I cannot combine it with my state management approaches.
techouse commentedon Sep 14, 2022
Using https://pub.dev/packages/infinite_scroll_pagination
SaswatOfficial commentedon Sep 23, 2022
can you provide the whole code including the tab bar with extended nested scroll view? I saw the documentation but am not able to implement it.
marcellocamara commentedon Oct 16, 2022
This bug is still reproducible on
Flutter 3.3.4withDart 2.18.2.I'm not using
AutomaticKeepAliveClientMixin, justDefaultTabControllerwithNestedScrollViewandTabBarwithTabViewon the body.The
TabViewchildren does not haveAutomaticKeepAliveClientMixin. Just a stateless widget.All the pages scroll together, scrolling only one. And sometimes have this crash:
No workarounds yet? I don't want to use any package to "avoid" it.
farmerswalker commentedon Feb 28, 2023
anything update?
dam-ease commentedon May 8, 2023
I am able to reproduce this issue on the latest
masterandstablechannels.Code Sample
flutter doctor -v
[✓] Flutter (Channel master, 3.11.0-2.0.pre.55, on macOS 13.3 22E252 darwin-arm64, locale en-NG) • Flutter version 3.11.0-2.0.pre.55 on channel master at /Users/dammya/fvm/versions/master • Upstream repository https://github.com/flutter/flutter.git • Framework revision 835b892d7f (2 days ago), 2023-05-07 01:30:22 +0530 • Engine revision 23f730efbf • Dart version 3.1.0 (build 3.1.0-83.0.dev) • DevTools version 2.23.1 [✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at /Users/dammya/Library/Android/sdk • Platform android-33, build-tools 32.1.0-rc1 • ANDROID_HOME = /Users/dammya/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • 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 2021.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 11.0.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2022.3.2) • IntelliJ at /Applications/IntelliJ IDEA CE.app • 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 [✓] VS Code (version 1.78.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.50.0 [✓] VS Code (version 1.78.0) • VS Code at /Users/dammya/.Trash/Visual Studio Code 20.07.05.app/Contents • Flutter extension version 3.50.0 [✓] Connected device (4 available) • sdk gphone arm64 (mobile) • emulator-5554 • android-arm64 • Android 11 (API 30) (emulator) • iPhone 14 Pro Max (mobile) • D7F3302D-D66F-4B89-B8CF-DBEE1CDB5449 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.3 22E252 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 112.0.5615.137 [✓] Network resources • All expected network resources are available. • No issues found![✓] Flutter (Channel stable, 3.7.12, on macOS 13.3 22E252 darwin-arm64, locale en-NG) • Flutter version 3.7.12 on channel stable at /Users/dammya/sdks/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 4d9e56e694 (3 weeks ago), 2023-04-17 21:47:46 -0400 • Engine revision 1a65d409c7 • Dart version 2.19.6 • DevTools version 2.20.1 [✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at /Users/dammya/Library/Android/sdk • Platform android-33, build-tools 32.1.0-rc1 • ANDROID_HOME = /Users/dammya/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • 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 2021.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 11.0.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2022.3.2) • IntelliJ at /Applications/IntelliJ IDEA CE.app • 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 [✓] VS Code (version 1.78.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.50.0 [✓] VS Code (version 1.78.0) • VS Code at /Users/dammya/.Trash/Visual Studio Code 20.07.05.app/Contents • Flutter extension version 3.50.0 [✓] Connected device (4 available) • sdk gphone arm64 (mobile) • emulator-5554 • android-arm64 • Android 11 (API 30) (emulator) • iPhone 14 Pro Max (mobile) • D7F3302D-D66F-4B89-B8CF-DBEE1CDB5449 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.3 22E252 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 112.0.5615.137 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found!Piinks commentedon May 30, 2023
I am going to close this to refer to #40740, which is the root issue here and has the most upvotes and information. Thank you for providing more test cases!
github-actions commentedon Jun 13, 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.