Open lkp-k opened 9 months ago
Thanks for the report. I can reproduce this issue with below minimal sample code.
As far as I can see, this is a known issue with nested navigation: https://github.com/flutter/flutter/issues/85603. You can take a look at https://github.com/flutter/flutter/issues/85603#issuecomment-876798161 where the solution is pointing out there.
It seems we need to pass PrimaryScrollController
down to shell route in the stack, but I haven't found a way to do it now. Labeling the issue for more ideas.
Thank you so much. I checked out the suggestion and it does work, and please let me know if I can help in some way as well.
Sorry I'm unfortunately not a pro at the internals of flutter implementations (trying to build MVPs fast) so please ignore this if it is wildly incorrect but since you offer GoRouter.of(context), would it made sense to offer a list or map of PrimaryScrollController per stack there, so for ex. GoRouter.of(context).primaryScrollControllers.byKey()?
In my case, I am using riverpod so I just created a primary scroll state, and utilized the key map. It does work, but it does feel like an unnecessary thing. Maybe the underlying StatefulNavigationShell can make a list, and use the index (already being used to show the right route) to give the right scroll controller in the context.
We have this on our app as well. Nothing new to add, but happy to pay for a coffee for someone to fix it ☕
Is there an existing issue for this?
Steps to reproduce
Expected results
Tapping the status bar should scroll to the top. For some reason using the navigationShell breaks this functionality.
Actual results
Scroll to top is not working.
Code sample
Router Setup
```dart final _rootNavigatorKey = GlobalKeyUsing body: navigationShell breaks the scroll to top functionality
```dart class Gatekeeper extends HookConsumerWidget { final StatefulNavigationShell navigationShell; const Gatekeeper({ Key? key, required this.navigationShell, }) : super(key: key ?? const ValueKey('ScaffoldWithNestedNavigation')); void goBranch(int index) { navigationShell.goBranch( index, initialLocation: index == navigationShell.currentIndex, ); } Widget build(context, ref) { return Scaffold( key: key, body: navigationShell, // <----- this is what causes the issue. Replace this with anything else, like a ListView with 50 elements, and tapping status bar to scroll top should work bottomNavigationBar: BottomNavigationBar( showSelectedLabels: false, showUnselectedLabels: false, selectedFontSize: 12, unselectedFontSize: 12, iconSize: 25, currentIndex: navigationShell.currentIndex, onTap: goBranch, items: [ const BottomNavigationBarItem( icon: Icon(MaterialCommunityIcons.calendar_check_outline), label: "Home", ), ], ), ); } } ```Home example
```dart class HomeScreen extends StatelessWidget { @override Widget build(context) { final items = ListScreenshots or Video
Screenshots / Video demonstration
[Upload media here]Logs
Logs
```console [Paste your logs here] ```Flutter Doctor output
Doctor output
```console [✓] Flutter (Channel stable, 3.10.6, on macOS 13.4.1 22F770820d darwin-x64, locale en-US) • Flutter version 3.10.6 on channel stable at /usr/local/Caskroom/flutter/2.2.3/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f468f3366c (3 weeks 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.1.0-rc1) • Android SDK at /Users/lkp-k/Library/Android/sdk • Platform android-33, build-tools 32.1.0-rc1 • ANDROID_HOME = /Users/lkp-k/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.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 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) [✓] VS Code (version 1.80.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.70.0 [✓] Connected device (3 available) • DARK MODE (mobile) • 00000000-000000000000000 • ios • iOS 16.5.1 20F75 • macOS (desktop) • macos • darwin-x64 • macOS 13.4.1 22F770820d darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.114 [✓] Network resources • All expected network resources are available. ```