From 47cc9266491d37e42cee434f54cfcb47d39b26d1 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 26 Apr 2024 13:52:08 +0800 Subject: [PATCH 1/7] chore: Update example to go_router 14 --- packages/go_router_builder/example/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router_builder/example/pubspec.yaml b/packages/go_router_builder/example/pubspec.yaml index c9a2bd938c7d..96d3a286010f 100644 --- a/packages/go_router_builder/example/pubspec.yaml +++ b/packages/go_router_builder/example/pubspec.yaml @@ -9,7 +9,7 @@ dependencies: collection: ^1.15.0 flutter: sdk: flutter - go_router: ^10.0.0 + go_router: ^14.0.0 provider: 6.0.5 dev_dependencies: From 7cd93bbede42b2873b33e2e68f87f75859d6cf48 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 26 Apr 2024 13:52:34 +0800 Subject: [PATCH 2/7] docs: Add example with on exit --- .../example/lib/on_exit_example.dart | 96 +++++++++++++++++++ .../example/lib/on_exit_example.g.dart | 58 +++++++++++ 2 files changed, 154 insertions(+) create mode 100644 packages/go_router_builder/example/lib/on_exit_example.dart create mode 100644 packages/go_router_builder/example/lib/on_exit_example.g.dart diff --git a/packages/go_router_builder/example/lib/on_exit_example.dart b/packages/go_router_builder/example/lib/on_exit_example.dart new file mode 100644 index 000000000000..b574c852c6e4 --- /dev/null +++ b/packages/go_router_builder/example/lib/on_exit_example.dart @@ -0,0 +1,96 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// ignore_for_file: public_member_api_docs, unreachable_from_main + +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; + +part 'on_exit_example.g.dart'; + +void main() => runApp(App()); + +class App extends StatelessWidget { + App({super.key}); + + @override + Widget build(BuildContext context) => MaterialApp.router( + routerConfig: _router, + title: _appTitle, + ); + + final GoRouter _router = GoRouter(routes: $appRoutes); +} + +@TypedGoRoute( + path: '/', + routes: >[ + TypedGoRoute(path: 'sub-route') + ], +) +class HomeRoute extends GoRouteData { + const HomeRoute(); + + @override + Widget build(BuildContext context, GoRouterState state) => const HomeScreen(); +} + +class SubRoute extends GoRouteData { + const SubRoute(); + + @override + Future onExit(BuildContext context, GoRouterState state) async { + final bool? confirmed = await showDialog( + context: context, + builder: (_) => AlertDialog( + content: const Text('Are you sure to leave this page?'), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(false), + child: const Text('Cancel'), + ), + ElevatedButton( + onPressed: () => Navigator.of(context).pop(true), + child: const Text('Confirm'), + ), + ], + ), + ); + return confirmed ?? false; + } + + @override + Widget build(BuildContext context, GoRouterState state) => const SubScreen(); +} + +class HomeScreen extends StatelessWidget { + const HomeScreen({super.key}); + + @override + Widget build(BuildContext context) => Scaffold( + appBar: AppBar(title: const Text(_appTitle)), + body: Center( + child: ElevatedButton( + onPressed: () => const SubRoute().go(context), + child: const Text('Go to sub screen'), + ), + )); +} + +class SubScreen extends StatelessWidget { + const SubScreen({super.key}); + + @override + Widget build(BuildContext context) => Scaffold( + appBar: AppBar(title: const Text('$_appTitle Sub screen')), + body: Center( + child: ElevatedButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text('Go back'), + ), + ), + ); +} + +const String _appTitle = 'GoRouter Example: builder'; diff --git a/packages/go_router_builder/example/lib/on_exit_example.g.dart b/packages/go_router_builder/example/lib/on_exit_example.g.dart new file mode 100644 index 000000000000..8a99156d8bfe --- /dev/null +++ b/packages/go_router_builder/example/lib/on_exit_example.g.dart @@ -0,0 +1,58 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: always_specify_types, public_member_api_docs + +part of 'on_exit_example.dart'; + +// ************************************************************************** +// GoRouterGenerator +// ************************************************************************** + +List get $appRoutes => [ + $homeRoute, + ]; + +RouteBase get $homeRoute => GoRouteData.$route( + path: '/', + factory: $HomeRouteExtension._fromState, + routes: [ + GoRouteData.$route( + path: 'sub-route', + factory: $SubRouteExtension._fromState, + ), + ], + ); + +extension $HomeRouteExtension on HomeRoute { + static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); + + String get location => GoRouteData.$location( + '/', + ); + + void go(BuildContext context) => context.go(location); + + Future push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); + + void replace(BuildContext context) => context.replace(location); +} + +extension $SubRouteExtension on SubRoute { + static SubRoute _fromState(GoRouterState state) => const SubRoute(); + + String get location => GoRouteData.$location( + '/sub-route', + ); + + void go(BuildContext context) => context.go(location); + + Future push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); + + void replace(BuildContext context) => context.replace(location); +} From 347f108ab4c098fa8de324c51162aaa7a9ea6346 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 26 Apr 2024 13:52:58 +0800 Subject: [PATCH 3/7] test: Add test with on exit --- .../example/test/on_exit_example_test.dart | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 packages/go_router_builder/example/test/on_exit_example_test.dart diff --git a/packages/go_router_builder/example/test/on_exit_example_test.dart b/packages/go_router_builder/example/test/on_exit_example_test.dart new file mode 100644 index 000000000000..e41adb0c6181 --- /dev/null +++ b/packages/go_router_builder/example/test/on_exit_example_test.dart @@ -0,0 +1,46 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:go_router_builder_example/on_exit_example.dart'; + +void main() { + testWidgets('It should trigger the on exit when leaving the route', + (WidgetTester tester) async { + await tester.pumpWidget(App()); + expect(find.byType(HomeScreen), findsOne); + + await tester.tap(find.widgetWithText(ElevatedButton, 'Go to sub screen')); + await tester.pumpAndSettle(); + + expect(find.byType(SubScreen), findsOne); + + await tester.tap(find.widgetWithText(ElevatedButton, 'Go back')); + await tester.pumpAndSettle(); + + expect( + find.widgetWithText(AlertDialog, 'Are you sure to leave this page?'), + findsOne, + ); + await tester.tap(find.text('Cancel')); + await tester.pumpAndSettle(); + + expect(find.byType(HomeScreen), findsNothing); + expect(find.byType(SubScreen), findsOne); + + await tester.tap(find.widgetWithText(ElevatedButton, 'Go back')); + await tester.pumpAndSettle(); + + expect( + find.widgetWithText(AlertDialog, 'Are you sure to leave this page?'), + findsOne, + ); + await tester.tap(find.text('Confirm')); + await tester.pumpAndSettle(); + + expect(find.byType(HomeScreen), findsOne); + expect(find.byType(SubScreen), findsNothing); + }); +} From cbf941b5f555209e4c99727784f0bfab64ec8148 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 26 Apr 2024 13:55:58 +0800 Subject: [PATCH 4/7] docs: Update changelogs --- packages/go_router_builder/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index e4ea9f6782ce..afb361d48ea7 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +- Adds an example and a test with `onExit`. + ## 2.6.0 * Adds support for passing observers to the StatefulShellBranch for the nested Navigator. From 4a7836ac7f29adf411a7115232558ef51173fd7d Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Tue, 14 May 2024 11:10:26 +0800 Subject: [PATCH 5/7] chore: Use go_router ^14.1.1 in example --- packages/go_router_builder/example/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router_builder/example/pubspec.yaml b/packages/go_router_builder/example/pubspec.yaml index 96d3a286010f..e550b5fd5286 100644 --- a/packages/go_router_builder/example/pubspec.yaml +++ b/packages/go_router_builder/example/pubspec.yaml @@ -9,7 +9,7 @@ dependencies: collection: ^1.15.0 flutter: sdk: flutter - go_router: ^14.0.0 + go_router: ^14.1.1 provider: 6.0.5 dev_dependencies: From 0f8be0eab8c98ecbe722169a431a3301955080a0 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Tue, 14 May 2024 14:30:48 +0800 Subject: [PATCH 6/7] chore: Update minimum sdk version --- packages/go_router_builder/example/pubspec.yaml | 2 +- packages/go_router_builder/pubspec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/go_router_builder/example/pubspec.yaml b/packages/go_router_builder/example/pubspec.yaml index e550b5fd5286..bc02b13402eb 100644 --- a/packages/go_router_builder/example/pubspec.yaml +++ b/packages/go_router_builder/example/pubspec.yaml @@ -3,7 +3,7 @@ description: go_router_builder examples publish_to: none environment: - sdk: ^3.1.0 + sdk: ^3.2.0 dependencies: collection: ^1.15.0 diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 82b41bb5f67a..65ca0b982d51 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -7,8 +7,8 @@ repository: https://github.com/flutter/packages/tree/main/packages/go_router_bui issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22 environment: - sdk: ^3.1.0 - flutter: ">=3.13.0" + sdk: ^3.2.0 + flutter: ">=3.16.0" dependencies: analyzer: ">=5.2.0 <7.0.0" From 3525d646ab8c32ec0bc55fb1bcaed29539dab85f Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Tue, 14 May 2024 16:11:20 +0800 Subject: [PATCH 7/7] chore: Update version to 2.7.0 --- packages/go_router_builder/CHANGELOG.md | 3 ++- packages/go_router_builder/pubspec.yaml | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 82e8d1951286..3332a70e1b8d 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 2.7.0 - Adds an example and a test with `onExit`. +- Updates minimum supported SDK version to Flutter 3.16/Dart 3.2. ## 2.6.2 diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 65ca0b982d51..0e6e10b6b3d6 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -2,7 +2,7 @@ name: go_router_builder description: >- A builder that supports generated strongly-typed route helpers for package:go_router -version: 2.6.2 +version: 2.7.0 repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22 @@ -26,7 +26,7 @@ dev_dependencies: dart_style: 2.3.6 flutter: sdk: flutter - go_router: ^10.0.0 + go_router: ^14.0.0 test: ^1.20.0 topics: