1
- import 'package:flutter/widgets.dart' ;
2
1
import 'package:flutter_news_example/article/article.dart' ;
3
2
import 'package:flutter_news_example/home/home.dart' ;
4
3
import 'package:flutter_news_example/login/login.dart' ;
@@ -10,107 +9,56 @@ import 'package:flutter_news_example/slideshow/slideshow.dart';
10
9
import 'package:flutter_news_example/subscriptions/view/manage_subscription_page.dart' ;
11
10
import 'package:flutter_news_example/user_profile/user_profile.dart' ;
12
11
import 'package:go_router/go_router.dart' ;
13
- import 'package:news_blocks/news_blocks.dart' ;
14
12
15
13
final GoRouter router = GoRouter (
16
14
routes: < RouteBase > [
17
15
GoRoute (
18
16
path: HomePage .routePath,
19
- builder: (BuildContext context, GoRouterState state) {
20
- return const HomePage ();
21
- },
17
+ builder: HomePage .routeBuilder,
22
18
routes: < RouteBase > [
23
19
GoRoute (
24
20
name: NetworkErrorPage .routePath,
25
21
path: NetworkErrorPage .routePath,
26
- builder: (BuildContext context, GoRouterState state) {
27
- final onRetry = state.extra as VoidCallback ? ;
28
- return NetworkError (onRetry: onRetry);
29
- },
22
+ builder: NetworkErrorPage .routeBuilder,
30
23
),
31
24
GoRoute (
32
25
name: LoginWithEmailPage .routePath,
33
26
path: LoginWithEmailPage .routePath,
34
- builder: (BuildContext context, GoRouterState state) {
35
- return const LoginWithEmailPage ();
36
- },
27
+ builder: LoginWithEmailPage .routeBuilder,
37
28
routes: < RouteBase > [
38
29
GoRoute (
39
30
name: MagicLinkPromptPage .routePath,
40
31
path: MagicLinkPromptPage .routePath,
41
- builder: (BuildContext context, GoRouterState state) {
42
- return MagicLinkPromptPage (
43
- email: state.uri.queryParameters['email' ]! ,
44
- );
45
- },
32
+ builder: MagicLinkPromptPage .routeBuilder,
46
33
),
47
34
],
48
35
),
49
36
GoRoute (
50
37
name: ArticlePage .routeName,
51
38
path: ArticlePage .routePath,
52
- builder: (BuildContext context, GoRouterState state) {
53
- final id = state.pathParameters['id' ];
54
-
55
- final isVideoArticle = bool .tryParse (
56
- state.uri.queryParameters['isVideoArticle' ] ?? 'false' ,
57
- ) ??
58
- false ;
59
- final interstitialAdBehavior =
60
- state.uri.queryParameters['interstitialAdBehavior' ] != null
61
- ? InterstitialAdBehavior .values.firstWhere (
62
- (e) =>
63
- e.toString () ==
64
- 'InterstitialAdBehavior.'
65
- // ignore: lines_longer_than_80_chars
66
- '${state .uri .queryParameters ['interstitialAdBehavior' ]}' ,
67
- )
68
- : null ;
69
-
70
- if (id == null ) {
71
- throw Exception ('Missing required "id" parameter' );
72
- }
73
-
74
- return ArticlePage (
75
- id: id,
76
- isVideoArticle: isVideoArticle,
77
- interstitialAdBehavior:
78
- interstitialAdBehavior ?? InterstitialAdBehavior .onOpen,
79
- );
80
- },
39
+ builder: ArticlePage .routeBuilder,
81
40
routes: < RouteBase > [
82
41
GoRoute (
83
42
name: SlideshowPage .routePath,
84
43
path: SlideshowPage .routePath,
85
- builder: (BuildContext context, GoRouterState state) {
86
- return SlideshowPage (
87
- slideshow: state.extra! as SlideshowBlock ,
88
- articleId: state.pathParameters['id' ]! ,
89
- );
90
- },
44
+ builder: SlideshowPage .routeBuilder,
91
45
),
92
46
],
93
47
),
94
48
GoRoute (
95
49
name: UserProfilePage .routePath,
96
50
path: UserProfilePage .routePath,
97
- builder: (BuildContext context, GoRouterState state) {
98
- return const UserProfilePage ();
99
- },
51
+ builder: UserProfilePage .routeBuilder,
100
52
routes: < RouteBase > [
101
53
GoRoute (
102
54
name: ManageSubscriptionPage .routePath,
103
55
path: ManageSubscriptionPage .routePath,
104
- builder: (BuildContext context, GoRouterState state) {
105
- return const ManageSubscriptionPage ();
106
- },
56
+ builder: ManageSubscriptionPage .routeBuilder,
107
57
),
108
58
GoRoute (
109
59
name: NotificationPreferencesPage .routePath,
110
60
path: NotificationPreferencesPage .routePath,
111
- builder: (BuildContext context, GoRouterState state) {
112
- return const NotificationPreferencesPage ();
113
- },
61
+ builder: NotificationPreferencesPage .routeBuilder,
114
62
),
115
63
],
116
64
),
@@ -119,9 +67,7 @@ final GoRouter router = GoRouter(
119
67
GoRoute (
120
68
name: OnboardingPage .routePath,
121
69
path: OnboardingPage .routePath,
122
- builder: (BuildContext context, GoRouterState state) {
123
- return const OnboardingPage ();
124
- },
70
+ builder: OnboardingPage .routeBuilder,
125
71
),
126
72
],
127
73
);
0 commit comments