Skip to content

Commit 75e6e43

Browse files
johnpryanloic-sharmachunhtai
authored
[go_router] Refactor internal classes and methods (#2317)
* Refactor internal classes and methods - Separate matching from redirection - Add RouteRedirector typedef - Add RouteMatcher class - Add RouteBuilder class - Add RouteConfiguration class - Rename and reorganize internal classes and libraries - Add todo comments * format * Sort imports * Update changelog * Address code review comments - Change name back to GoRouterRefreshStream - Update toString() methods for new naming - Make fields final - Add logging to parser - Add comments - add tests - Move function-scope to new library-scope _addRedirect function - import widgets instead of material where possible * remove routing library * Move classes in go_router.dart into separate libraries * Move Configuration.validate() into constructor * Remove comment * use continue in redirect loop * Fix comments * Sort imports * Fix logging in configuration * add visibleForTesting annotation * Updates from merge with main * Format * Add TODOs to make Router implementation classes private * Add copyright headers * Fix tests * format * fix comment * Update packages/go_router/lib/src/parser.dart Co-authored-by: Loïc Sharma <[email protected]> * add whitespace * format * Hide typedefs that weren't previously exported * Delete empty file * add missing import * Specify version 4.1.2 in pubspec.yaml * Update packages/go_router/lib/src/builder.dart Co-authored-by: chunhtai <[email protected]> * Fix comment * Add isError and error getters to RouteMatchList * Add issue links to TODO comments * Add link to issue for TODO * Re-apply code from #2306 due to merge conflicts * Add issue references Co-authored-by: Loïc Sharma <[email protected]> Co-authored-by: chunhtai <[email protected]>
1 parent 199d8c9 commit 75e6e43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1310
-922
lines changed

packages/go_router/.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
.packages
30+
build/

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.2.1
2+
3+
- Refactors internal classes and methods
4+
15
## 4.2.0
26

37
- Adds `void replace()` and `replaceNamed` to `GoRouterDelegate`, `GoRouter` and `GoRouterHelper`.

packages/go_router/example/lib/books/src/auth.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'package:flutter/widgets.dart';
66

7-
/// A mock authentication service
7+
/// A mock authentication service.
88
class BookstoreAuth extends ChangeNotifier {
99
bool _signedIn = false;
1010

packages/go_router/example/lib/books/src/screens/scaffold.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
77

88
import 'package:go_router/go_router.dart';
99

10-
/// The enum for scaffold tab
10+
/// The enum for scaffold tab.
1111
enum ScaffoldTab {
1212
/// The books tab.
1313
books,

packages/go_router/example/lib/cupertino.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:go_router/go_router.dart';
77

88
void main() => runApp(App());
99

10-
/// The main app
10+
/// The main app.
1111
class App extends StatelessWidget {
1212
/// Creates an [App].
1313
App({Key? key}) : super(key: key);

packages/go_router/example/lib/error_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Page2Screen extends StatelessWidget {
8585
);
8686
}
8787

88-
/// The screen of the error page
88+
/// The screen of the error page.
8989
class ErrorScreen extends StatelessWidget {
9090
/// Creates an [ErrorScreen].
9191
const ErrorScreen(this.error, {Key? key}) : super(key: key);

packages/go_router/example/lib/router_stream_refresh.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class _AppState extends State<App> {
8484
return null;
8585
},
8686
// changes on the listenable will cause the router to refresh it's route
87+
// TODO(johnpryan): Deprecate GoRouterRefreshStream
88+
// See https://github.com/flutter/flutter/issues/108128
8789
refreshListenable: GoRouterRefreshStream(loggedInState.stream),
8890
);
8991
super.initState();

packages/go_router/example/lib/shared_scaffold.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class SharedScaffold extends StatefulWidget {
7979
Key? key,
8080
}) : super(key: key);
8181

82-
/// The selected index
82+
/// The selected index.
8383
final int selectedIndex;
8484

8585
/// The body of the page.
@@ -173,7 +173,7 @@ class Page2View extends StatelessWidget {
173173

174174
/// The error scaffold.
175175
class ErrorScaffold extends StatelessWidget {
176-
/// Creates an [ErrorScaffold]
176+
/// Creates an [ErrorScaffold].
177177
const ErrorScaffold({
178178
required this.body,
179179
Key? key,

packages/go_router/example/lib/transitions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class ExampleTransitionsScreen extends StatelessWidget {
137137
/// The color of the container.
138138
final Color color;
139139

140-
/// The transition kind
140+
/// The transition kind.
141141
final String kind;
142142

143143
@override

packages/go_router/lib/go_router.dart

Lines changed: 9 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3,106 +3,15 @@
33
// found in the LICENSE file.
44

55
/// A declarative router for Flutter based on Navigation 2 supporting
6-
/// deep linking, data-driven routes and more
6+
/// deep linking, data-driven routes and more.
77
library go_router;
88

9-
import 'package:flutter/widgets.dart';
10-
11-
import 'src/go_router.dart';
12-
13-
export 'src/custom_transition_page.dart';
14-
export 'src/go_route.dart';
15-
export 'src/go_router.dart';
16-
export 'src/go_router_refresh_stream.dart';
17-
export 'src/go_router_state.dart';
18-
export 'src/inherited_go_router.dart';
19-
export 'src/route_data.dart' show GoRouteData, TypedGoRoute;
9+
export 'src/configuration.dart' show GoRouterState, GoRoute;
10+
export 'src/misc/extensions.dart';
11+
export 'src/misc/inherited_router.dart';
12+
export 'src/misc/refresh_stream.dart';
13+
export 'src/pages/custom_transition_page.dart';
14+
export 'src/platform.dart' show UrlPathStrategy;
15+
export 'src/router.dart';
16+
export 'src/typed_routing.dart' show GoRouteData, TypedGoRoute;
2017
export 'src/typedefs.dart' show GoRouterPageBuilder, GoRouterRedirect;
21-
export 'src/url_path_strategy.dart';
22-
23-
/// Dart extension to add navigation function to a BuildContext object, e.g.
24-
/// context.go('/');
25-
// NOTE: adding this here instead of in /src to work-around a Dart analyzer bug
26-
// and fix: https://github.com/csells/go_router/issues/116
27-
extension GoRouterHelper on BuildContext {
28-
/// Get a location from route name and parameters.
29-
String namedLocation(
30-
String name, {
31-
Map<String, String> params = const <String, String>{},
32-
Map<String, String> queryParams = const <String, String>{},
33-
}) =>
34-
GoRouter.of(this)
35-
.namedLocation(name, params: params, queryParams: queryParams);
36-
37-
/// Navigate to a location.
38-
void go(String location, {Object? extra}) =>
39-
GoRouter.of(this).go(location, extra: extra);
40-
41-
/// Navigate to a named route.
42-
void goNamed(
43-
String name, {
44-
Map<String, String> params = const <String, String>{},
45-
Map<String, String> queryParams = const <String, String>{},
46-
Object? extra,
47-
}) =>
48-
GoRouter.of(this).goNamed(
49-
name,
50-
params: params,
51-
queryParams: queryParams,
52-
extra: extra,
53-
);
54-
55-
/// Push a location onto the page stack.
56-
void push(String location, {Object? extra}) =>
57-
GoRouter.of(this).push(location, extra: extra);
58-
59-
/// Navigate to a named route onto the page stack.
60-
void pushNamed(
61-
String name, {
62-
Map<String, String> params = const <String, String>{},
63-
Map<String, String> queryParams = const <String, String>{},
64-
Object? extra,
65-
}) =>
66-
GoRouter.of(this).pushNamed(
67-
name,
68-
params: params,
69-
queryParams: queryParams,
70-
extra: extra,
71-
);
72-
73-
/// Replaces the top-most page of the page stack with the given URL location
74-
/// w/ optional query parameters, e.g. `/family/f2/person/p1?color=blue`.
75-
///
76-
/// See also:
77-
/// * [go] which navigates to the location.
78-
/// * [push] which pushes the location onto the page stack.
79-
void replace(String location, {Object? extra}) =>
80-
GoRouter.of(this).replace(location, extra: extra);
81-
82-
/// Replaces the top-most page of the page stack with the named route w/
83-
/// optional parameters, e.g. `name='person', params={'fid': 'f2', 'pid':
84-
/// 'p1'}`.
85-
///
86-
/// See also:
87-
/// * [goNamed] which navigates a named route.
88-
/// * [pushNamed] which pushes a named route onto the page stack.
89-
void replaceNamed(
90-
String name, {
91-
Map<String, String> params = const <String, String>{},
92-
Map<String, String> queryParams = const <String, String>{},
93-
Object? extra,
94-
}) =>
95-
GoRouter.of(this).replaceNamed(
96-
name,
97-
params: params,
98-
queryParams: queryParams,
99-
extra: extra,
100-
);
101-
102-
/// Returns `true` if there is more than 1 page on the stack.
103-
bool canPop() => GoRouter.of(this).canPop();
104-
105-
/// Pop the top page off the Navigator's page stack by calling
106-
/// [Navigator.pop].
107-
void pop() => GoRouter.of(this).pop();
108-
}

0 commit comments

Comments
 (0)