mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Fix web navigation bug in game_template (#1868)
Disallow navigating to /win without details. Fixes #1288. ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing.
This commit is contained in:
@@ -157,6 +157,16 @@ class MyApp extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'won',
|
path: 'won',
|
||||||
|
redirect: (context, state) {
|
||||||
|
if (state.extra == null) {
|
||||||
|
// Trying to navigate to a win screen without any data.
|
||||||
|
// Possibly by using the browser's back button.
|
||||||
|
return '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, do not redirect.
|
||||||
|
return null;
|
||||||
|
},
|
||||||
pageBuilder: (context, state) {
|
pageBuilder: (context, state) {
|
||||||
final map = state.extra! as Map<String, dynamic>;
|
final map = state.extra! as Map<String, dynamic>;
|
||||||
final score = map['score'] as Score;
|
final score = map['score'] as Score;
|
||||||
|
|||||||
Reference in New Issue
Block a user