Closed
Description
Steps to Reproduce
- Execute
flutter run
on the code sample - navigate as follow
- push /b
- go back
- go to /c
- push /d
- push /d/e
Expected results:
- After step
i
the page should be on top of the shell route - In step
v
we should be able to go to/d/e
Actual results:
- After step
i
the page is inside the shell - In step
v
we can't go to/d/e
Code sample
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
void main() => runApp(const ProviderScope(child: MyApp()));
final GlobalKey<NavigatorState> _rootNavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'root');
final GlobalKey<NavigatorState> _shellNavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'shell');
final routesProvider = Provider<GoRouter>(
(ref) {
return GoRouter(
debugLogDiagnostics: true,
initialLocation: '/a',
navigatorKey: _rootNavigatorKey,
routes: [
ShellRoute(
navigatorKey: _shellNavigatorKey,
builder: (context, state, child) => ShellWidget(child: child),
routes: [
GoRoute(
path: '/a',
builder: (context, state) => const DummyScreen(
color: Colors.green,
text: '/b',
),
),
GoRoute(
path: '/c',
builder: (context, state) => const DummyScreen(
color: Colors.green,
text: '/d',
),
),
],
),
GoRoute(
path: '/d',
parentNavigatorKey: _rootNavigatorKey,
builder: (context, state) => const DummyScreen(
color: Colors.red,
text: '/d/e',
),
routes: [
GoRoute(
// can't push this page at all
path: 'e',
builder: (context, state) => const DummyScreen(
color: Colors.red,
text: '/c',
),
),
],
),
GoRoute(
// can't push this page on the shell without key
// even though it is outside of shell route
path: '/b',
builder: (context, state) => const DummyScreen(
color: Colors.green,
text: '',
),
),
],
);
},
);
class ShellWidget extends StatefulWidget {
const ShellWidget({
super.key,
required this.child,
});
final Widget child;
@override
State<ShellWidget> createState() => _ShellWidgetState();
}
class _ShellWidgetState extends State<ShellWidget> {
int index = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Hello")),
bottomNavigationBar: BottomNavigationBar(
currentIndex: index,
onTap: (value) {
setState(() {
index = value;
switch (value) {
case 0:
context.go('/a');
break;
case 1:
context.go('/c');
break;
default:
}
});
},
items: const [
BottomNavigationBarItem(
icon: Icon(
Icons.access_alarm,
),
label: 'a',
),
BottomNavigationBarItem(
icon: Icon(
Icons.access_alarm,
),
label: 'c',
),
],
),
body: widget.child,
);
}
}
class MyApp extends ConsumerWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final routes = ref.watch(routesProvider);
return MaterialApp.router(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
routeInformationParser: routes.routeInformationParser,
routeInformationProvider: routes.routeInformationProvider,
routerDelegate: routes.routerDelegate,
);
}
}
class DummyScreen extends StatelessWidget {
const DummyScreen({
super.key,
required this.color,
required this.text,
});
final Color color;
final String text;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(GoRouter.of(context).location)),
backgroundColor: color,
body: Center(
child: ElevatedButton(
onPressed: text.isNotEmpty ? () => context.push(text) : null,
child: Text(text),
),
),
);
}
}
Logs
- go_router debugLogDiagnostics
[GoRouter] Full paths for routes:
=> /d
=> /d/e
=> /b
[GoRouter] setting initial location /a
[GoRouter] Using MaterialApp configuration
[GoRouter] pushing /b
[GoRouter] going to /c
[GoRouter] pushing /d
[GoRouter] pushing /d/e
% flutter analyze
Analyzing bug...
No issues found! (ran in 1.4s)
% flutter doctor -v
[✓] Flutter (Channel beta, 3.4.0-17.2.pre, on macOS 12.6 21G115 darwin-arm, locale en-IN)
• Flutter version 3.4.0-17.2.pre on channel beta at /Users/padya/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision d6260f127f (2 weeks ago), 2022-09-21 13:33:49 -0500
• Engine revision 3950c6140a
• Dart version 2.19.0 (build 2.19.0-146.2.beta)
• DevTools version 2.16.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/padya/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14A400
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1)
• 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.11+0-b60-7772763)
[✓] IntelliJ IDEA Community Edition (version 2022.1.3)
• 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.72.0-insider)
• VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
• Flutter extension version 3.50.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.6 21G115 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 106.0.5249.103
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
video
Screen.Recording.2022-10-06.at.10.12.18.AM.mov
Metadata
Metadata
Assignees
Labels
Important issues not at the top of the work listFound to occur in 3.4Found to occur in 3.5The issue has been confirmed reproducible and is ready to work onThe go_router packageflutter/packages repository. See also p: labels.Issue is closed as already fixed in a newer versionOwned by Go Router teamTriaged by Go Router team