Repository navigation
GoRouter ShellRoute wrong official example and transition bug #122972
Description
Hi,
There is an en error on this official documentation (or maybe I am wrong): https://github.com/flutter/packages/blob/main/packages/go_router/example/lib/shell_route.dart
As you can see on the code, each Screen widget, starts with a "Scaffold". But they parent with BottomNavigation have also a Scaffold which duplicates the usage of Scaffold and in the widget tree we have 2 Scaffold.
On the flutter documentation we have this : https://api.flutter.dev/flutter/material/Scaffold-class.html#:~:text=It%20is%20typically,updates%20the%20AppBar
It is typically not necessary to nest Scaffolds.
On my app, I wanted to use only 1 shared Scaffold, but it cause a bug during transition. To replicate it, you can use this code: https://github.com/flutter/packages/blob/main/packages/go_router/example/lib/shell_route.dart
And just change the ScreenB widget content to this (just removing the Scaffold parent):
/// The second screen in the bottom navigation bar.
class ScreenB extends StatelessWidget {
/// Constructs a [ScreenB] widget.
const ScreenB({super.key});
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('Screen B'),
TextButton(
onPressed: () {
GoRouter.of(context).go('/b/details');
},
child: const Text('View B details'),
),
],
),
);
}
}Or see the real preview here: https://flutlab.io/editor/46151d54-95e1-49cf-9fe0-ad0afc469c76
Then, if you try to go from A Screen, to B Screen, you will the that there is a transition bug from the view A to B. Like this: (https://user-images.githubusercontent.com/13520683/226175787-7ccc910f-11b5-446c-a106-0f0ba1d79c22.webm)
untitled.webm
As you can see, there is no problem to go From A to C, because the A and C have their own Scaffold so duplicated Scaffolds with BottomNavigationBar. But as I removed the Scaffold from the Screen B to keep only 1 scaffold, there is a transition bug from A to B, C to B etc. But no problem from B to A, or C.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
exaby73 commentedon Mar 20, 2023
Hello @sovetski. This is expected since the Scaffold adds a background to the screen by default of white. Without the Scaffold, the background is transparent and therefore you see this effect. This is not a bug and is expected. You can extract your shared Scaffold into a reusable widget and use it on all screens. If you need more help with your code, I suggest finding help on various communities found on https://flutter.dev/community. Since this is not a bug, I am closing this issue. Thank you
sovetski commentedon Mar 20, 2023
Hi @exaby73,
As I mentionned, there is a Scaffold, that is why I don't understand why there is a problem. Did you checked this code? https://flutlab.io/editor/46151d54-95e1-49cf-9fe0-ad0afc469c76 You will see that there is a Scaffold, but instead of 2 Scaffold, on the Screen B, there is only 1 Scaffold so it is very strange behaviour.
I also tried to use a shared Scaffold but the problem is same. You can try it on your side and you will see that it is not working.
exaby73 commentedon Mar 20, 2023
The live preview does not load for me. Please try to include the code in code blocks in the comment itself, or use https://dartpad.dev to provide a code sample. But again, ultimately
ScreenBwill be shown, and sinceScreenBdoes not have aScaffold, it will be transparent. Also, lots of widgets rely on aScaffoldlikeScaffoldMessagerto showSnackBars, so you will get problems latersovetski commentedon Mar 20, 2023
@exaby73 sorry, maybe my explanation is wrong, I will try to explain again. ScreenB itself does not contain a Scaffold. But its parent widget ScaffoldWithNavBar does have a Scaffold. And since ScreenB is a child element of ScaffoldWithNavBar it does have a Scaffold. The reason why I remove the Scaffold from ScreenB is to avoid getting 2 Scaffold on my Widget tree as I mentioned in the issue description, the Flutter documentation says
There is the final code that you can try and see the problem.
See the code
exaby73 commentedon Mar 20, 2023
Okay I get it. From what I can see, the
builderis not being called during the transition, but rather only after the transition is over. I changed the background color ofScaffoldWithNavto red, and you can see in the video below that the red background only appears after the animation. I am not sure if this is intended behavior, therefore I'll label the issue for further insights from the teamCode Sample
Video demonstration
issue_122972_nZ9y9d9qOb.mp4
flutter doctor -v(Master)9 remaining items
remeoj commentedon Jul 8, 2023
I'm getting this issue as well! I don't feel like this should be WAI, I don't think we should have to nest Scaffolds. But going to wrap my widgets in a scaffold for now. I'm also finding this issue, particularly using GoRouter!
sovetski commentedon Sep 2, 2023
Any update on this?
I know the team has a lot of work to do already, but this problem has exists for a while. I would have liked to participate and make a pull request, but unfortunately I don't master flutter at this point
chikko80 commentedon Oct 18, 2023
Facing the exact same issue using Gorouter ShellRotue
yohanangulo commentedon Jan 27, 2024
yep, same here.
I had to do this because I don't want to use scaffolds in all my screens
GoRoute( path: Routes.collectionsScreen, pageBuilder: (context, state) { return const NoTransitionPage(child: CollectionsScreen()); }, ),SakshamKarnawat commentedon Aug 14, 2024
Facing the exact same issue. Using nested scaffolds for now..
songhee24 commentedon Nov 11, 2024
Hello everyone, I found this solution
I don't know if this solution is correct, but maybe it will help someone
finall result:
