mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Migrate veggieseasons to go_router (#1544)
* add go_router * wip migration to go_router * small fixes * home screen cleanup * remove unused * small fixes * details should be fullscreen dialog * remove comment * fix navigation outside the shell by using the correct navigation keys * add restoration id to all pages * test passing, but parts are commented out, wip * uncommented more test code * Add TODOs * fix lint issues * fix tests * use FadeTransitionPage * remove unnecessary builders * FadeTransitionPage same as CustomTransitionPage * add comments regarding relative routes * add missing pageKey * add missing const --------- Co-authored-by: Brett Morgan <brettmorgan@google.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:veggieseasons/data/preferences.dart';
|
||||
import 'package:veggieseasons/data/veggie.dart';
|
||||
@@ -15,14 +16,10 @@ class VeggieCategorySettingsScreen extends StatelessWidget {
|
||||
|
||||
final String? restorationId;
|
||||
|
||||
static String show(NavigatorState navigator) {
|
||||
return navigator.restorablePush(_routeBuilder);
|
||||
}
|
||||
|
||||
static Route<void> _routeBuilder(BuildContext context, Object? argument) {
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
const VeggieCategorySettingsScreen(restorationId: 'category'),
|
||||
static Page<void> pageBuilder(BuildContext context) {
|
||||
return const CupertinoPage(
|
||||
restorationId: 'router.categories',
|
||||
child: VeggieCategorySettingsScreen(restorationId: 'category'),
|
||||
title: 'Preferred Categories',
|
||||
);
|
||||
}
|
||||
@@ -99,14 +96,10 @@ class CalorieSettingsScreen extends StatelessWidget {
|
||||
static const min = 2600;
|
||||
static const step = 200;
|
||||
|
||||
static String show(NavigatorState navigator) {
|
||||
return navigator.restorablePush(_routeBuilder);
|
||||
}
|
||||
|
||||
static Route<void> _routeBuilder(BuildContext context, Object? argument) {
|
||||
return CupertinoPageRoute<void>(
|
||||
builder: (context) =>
|
||||
const CalorieSettingsScreen(restorationId: 'calorie'),
|
||||
static Page<void> pageBuilder(BuildContext context) {
|
||||
return const CupertinoPage<void>(
|
||||
restorationId: 'router.calorie',
|
||||
child: CalorieSettingsScreen(restorationId: 'calorie'),
|
||||
title: 'Calorie Target',
|
||||
);
|
||||
}
|
||||
@@ -198,7 +191,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
},
|
||||
),
|
||||
onPress: () {
|
||||
CalorieSettingsScreen.show(Navigator.of(context));
|
||||
context.go('/settings/calories');
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -213,7 +206,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
content: const SettingsNavigationIndicator(),
|
||||
onPress: () {
|
||||
VeggieCategorySettingsScreen.show(Navigator.of(context));
|
||||
context.go('/settings/categories');
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -242,13 +235,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
onPressed: () async {
|
||||
await prefs.restoreDefaults();
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context);
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
isDefaultAction: true,
|
||||
child: const Text('No'),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
onPressed: () => context.pop(),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user