-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
flutter/packages
#6238Labels
P2Important issues not at the top of the work listImportant issues not 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_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: 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
It seems there's nowhere to specify restorationScopeId to the ShellRouteData.
ShellRouteData.$route() clearly have restorationScopeId parameter, but it seems there's nowhere to pass.
(route_data.dart)
static ShellRoute $route<T extends ShellRouteData>({
required T Function(GoRouterState) factory,
GlobalKey<NavigatorState>? navigatorKey,
List<RouteBase> routes = const <RouteBase>[],
List<NavigatorObserver>? observers,
String? restorationScopeId,
})- Turn on "Don't keep activities" in Android developer options
- Run the code sample on an Android device
- Press floating action button to change counter
- Background the app, then return to it
Expected results
Counter value should be restored.
Should have some api to pass 'restorationScopeId' for TypedShellRoute or ShellRouteData.
Actual results
Counter value resets to 0.
Code sample
Code sample
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
part 'main.g.dart';
void main() => runApp(App());
class App extends StatelessWidget {
App({super.key});
@override
Widget build(BuildContext context) => MaterialApp.router(
routerConfig: _router,
restorationScopeId: 'app',
);
final GoRouter _router = GoRouter(
routes: $appRoutes,
initialLocation: CounterRouteData().location,
restorationScopeId: 'goRouter',
);
}
@TypedShellRoute<MyShellRouteData>(
// <------------------------------------- SHOULD HAVE 'restorationScopeId' PARAMETER OR SOMETHING
routes: <TypedRoute<RouteData>>[
TypedGoRoute<CounterRouteData>(path: '/counter'),
],
)
class MyShellRouteData extends ShellRouteData {
const MyShellRouteData();
@override
Page<void> pageBuilder(
BuildContext context,
GoRouterState state,
Widget navigator,
) {
return MaterialPage(
child: Scaffold(body: navigator),
restorationId: 'shell',
);
}
}
class CounterRouteData extends GoRouteData {
const CounterRouteData();
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return MaterialPage(
child: RestorableCounter(
restorationId: 'restorableCounter',
),
restorationId: 'restorableCounterMaterialPage',
);
}
}
class RestorableCounter extends StatefulWidget {
const RestorableCounter({super.key, this.restorationId});
final String? restorationId;
@override
State<RestorableCounter> createState() => _RestorableCounterState();
}
// The [State] object uses the [RestorationMixin] to make the current value
// of the counter restorable.
class _RestorableCounterState extends State<RestorableCounter>
with RestorationMixin {
// The current value of the counter is stored in a [RestorableProperty].
// During state restoration it is automatically restored to its old value.
// If no restoration data is available to restore the counter from, it is
// initialized to the specified default value of zero.
final RestorableInt _counter = RestorableInt(0);
// In this example, the restoration ID for the mixin is passed in through
// the [StatefulWidget]'s constructor.
@override
String? get restorationId => widget.restorationId;
@override
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
// All restorable properties must be registered with the mixin. After
// registration, the counter either has its old value restored or is
// initialized to its default value.
registerForRestoration(_counter, 'count');
}
void _incrementCounter() {
setState(() {
// The current value of the property can be accessed and modified via
// the value getter and setter.
_counter.value++;
});
}
@override
void dispose() {
_counter.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Restorable Counter'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'${_counter.value}',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.4.1 22F82 darwin-arm64, locale ko-KR)
• Flutter version 3.10.5 on channel stable at /Users/macbookprom1/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 796c8ef792 (5 weeks ago), 2023-06-13 15:51:02 -0700
• Engine revision 45f6e00911
• Dart version 3.0.5
• DevTools version 2.23.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/macbookprom1/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/macbookprom1/Library/Android/sdk
• Java binary at: /Users/macbookprom1/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10320515/Android
Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version openjdk version "17.0.6" 2023-01-17
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
• Xcode at /Applications/Xcode-beta.app/Contents/Developer
• Build 15A5195k
• CocoaPods version 1.12.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio
• Android Studio at /Users/macbookprom1/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.9848316/Android
Studio Preview.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.
[✓] Android Studio (version 2022.3)
• Android Studio at /Users/macbookprom1/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10320515/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 version "17.0.6" 2023-01-17
[✓] Proxy Configuration
• HTTP_PROXY is set
• NO_PROXY is 127.0.0.1, localhost, 10.*.*.*, 165.213.*.*, 168.219.*.*, 202.20.*.*, 112.107.220.*,
*.samsung.net, ::1
• NO_PROXY contains localhost
• NO_PROXY contains 127.0.0.1
• NO_PROXY contains ::1
[✓] Connected device (3 available)
• SM F926B (mobile) • R3CR40TJSKM • android-arm64 • Android 13 (API 33)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.4.1 22F82 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 114.0.5735.198
! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same
local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.rydmike
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not 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_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version