From 0071c662c3570139c0feffde127dbd92741e5b32 Mon Sep 17 00:00:00 2001 From: Filip Hracek Date: Sun, 4 Jun 2023 16:51:37 +0200 Subject: [PATCH] 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. --- game_template/lib/main.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/game_template/lib/main.dart b/game_template/lib/main.dart index 57f3cfbe3..90c1f02b0 100644 --- a/game_template/lib/main.dart +++ b/game_template/lib/main.dart @@ -157,6 +157,16 @@ class MyApp extends StatelessWidget { ), GoRoute( 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) { final map = state.extra! as Map; final score = map['score'] as Score;