-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
flutter/packages
#4713Closed
Copy link
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listfound 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.13has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-webWeb applications specificallyWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
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
- Run the code sample in a web browser (go_router 10.0.0)
- Go to page 1, check the page key value
- Go to page 2
- Click on the back button browser
Expected results
Page keys are consistent, and successful widget state restoration.
Actual results
The page key is changed when going back from the back button, so the widget state cannot be restored.
Code sample
Code sample
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() {
GoRouter.optionURLReflectsImperativeAPIs = true;
runApp(const MyApp());
}
final GoRouter _router = GoRouter(
routerNeglect: false,
routes: <RouteBase>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) {
return const HomeScreen();
},
routes: <RouteBase>[
GoRoute(
name: 'page_1',
path: 'page_1',
builder: (BuildContext context, GoRouterState state) {
return PageScreen1(pageKey: state.pageKey);
},
),
GoRoute(
name: 'page_2',
path: 'page_2',
builder: (BuildContext context, GoRouterState state) {
return const PageScreen2();
},
),
],
),
],
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: _router,
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Home Screen')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () async {
GoRouter.of(context).push('/page_1');
},
child: const Text('Go to the page 1 screen'),
),
],
),
),
);
}
}
class PageScreen1 extends StatefulWidget {
const PageScreen1({super.key, required this.pageKey});
final ValueKey<String> pageKey;
@override
State<PageScreen1> createState() => _PageScreen1State();
}
class _PageScreen1State extends State<PageScreen1> {
bool isLoaded = false;
@override
void initState() {
super.initState();
print('initState');
}
@override
void didChangeDependencies() {
Future<void>.delayed(const Duration(seconds: 2), () {
setState(() {
isLoaded = true;
});
});
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => true,
child: Scaffold(
appBar: AppBar(title: const Text('Page Screen 1')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
isLoaded
? Text(
'Page key: ${widget.pageKey.toString()}',
style: const TextStyle(
fontSize: 20, fontWeight: FontWeight.bold),
)
: const CircularProgressIndicator(),
const SizedBox(
height: 40,
),
ElevatedButton(
onPressed: () {
GoRouter.of(context).pushNamed('page_2');
},
child: const Text('Go back Page 2 screen'),
),
],
),
),
),
);
}
}
class PageScreen2 extends StatelessWidget {
const PageScreen2({super.key});
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => true,
child: Scaffold(
appBar: AppBar(title: const Text('Page Screen 2')),
body: const Center(child: Text('Page 2')),
),
);
}
}
Screenshots or Video
Screenshots / Video demonstration
Screen.Recording.2023-07-28.at.11.08.36.mov
Logs
Logs
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.3.4, on macOS 13.4.1 22F770820d darwin-x64, locale en-VN)
• Flutter version 3.3.4 on channel stable at /Users/hieuho/Documents/tools/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision eb6d86ee27 (10 months ago), 2022-10-04 22:31:45 -0700
• Engine revision c08d7d5efc
• Dart version 2.18.2
• DevTools version 2.15.0
[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at /Users/hieuho/Library/Android/sdk
• Platform android-33, build-tools 32.1.0-rc1
• Java binary at: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
• Java version Java(TM) SE Runtime Environment (build 1.8.0_333-b02)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E222b
• CocoaPods version 1.12.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio (version 2022.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
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
[✓] VS Code (version 1.80.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.68.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 13.4.1 22F770820d darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.114
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 2 categories.Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listfound 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.13has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-webWeb applications specificallyWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version