@@ -33,52 +33,51 @@ class MyApp extends StatelessWidget {
33
33
child: child! ,
34
34
),
35
35
initialRoute: '/' ,
36
- onGenerateInitialRoutes: (initialRoute) => [
37
- MaterialPageRoute (
38
- settings: RouteSettings (name: initialRoute),
39
- builder: (context) {
40
- String sanitizedRoute =
41
- initialRoute != '/' && initialRoute.startsWith ('/' )
42
- ? initialRoute.substring (1 )
43
- : initialRoute;
44
-
45
- return BouncingScrollWrapper .builder (
46
- context, buildPage (sanitizedRoute),
47
- dragWithMouse: true );
48
- })
49
- ],
36
+ onGenerateInitialRoutes: (initialRoute) {
37
+ final Uri uri = Uri .parse (initialRoute);
38
+ return [
39
+ buildPage (path: uri.path, queryParams: uri.queryParameters),
40
+ ];
41
+ },
50
42
onGenerateRoute: (RouteSettings settings) {
51
- return MaterialPageRoute (
52
- settings: RouteSettings (name: '/${settings .name }' ),
53
- builder: (context) {
54
- return BouncingScrollWrapper .builder (
55
- context, buildPage (settings.name ?? '' ),
56
- dragWithMouse: true );
57
- });
43
+ final Uri uri = Uri .parse (settings.name ?? '/' );
44
+ return buildPage (path: uri.path, queryParams: uri.queryParameters);
58
45
},
59
46
debugShowCheckedModeBanner: false ,
60
47
);
61
48
}
62
49
63
50
// onGenerateRoute route switcher.
64
51
// Navigate using the page name, `Navigator.pushNamed(context, ListPage.name)`.
65
- Widget buildPage (String name) {
66
- return MaxWidthBox (
67
- // A widget that limits the maximum width.
68
- // This is used to create a gutter area on either side of the content.
69
- maxWidth: 1200 ,
70
- background: Container (color: const Color (0xFFF5F5F5 )),
71
- child: switch (name) {
72
- '/' || ListPage .name => const ListPage (),
73
- PostPage .name =>
74
- // Custom "per-page" breakpoints.
75
- const ResponsiveBreakpoints (breakpoints: [
76
- Breakpoint (start: 0 , end: 480 , name: MOBILE ),
77
- Breakpoint (start: 481 , end: 1200 , name: TABLET ),
78
- Breakpoint (start: 1201 , end: double .infinity, name: DESKTOP ),
79
- ], child: PostPage ()),
80
- TypographyPage .name => const TypographyPage (),
81
- _ => const SizedBox .shrink (),
52
+ PageRoute buildPage (
53
+ {required String path, Map <String , String > queryParams = const {}}) {
54
+ return MaterialPageRoute (
55
+ settings: RouteSettings (
56
+ name: (path.startsWith ('/' ) == false ) ? '/$path ' : path),
57
+ builder: (context) {
58
+ String pathName =
59
+ path != '/' && path.startsWith ('/' ) ? path.substring (1 ) : path;
60
+ return BouncingScrollWrapper .builder (
61
+ context,
62
+ MaxWidthBox (
63
+ // A widget that limits the maximum width.
64
+ // This is used to create a gutter area on either side of the content.
65
+ maxWidth: 1200 ,
66
+ background: Container (color: const Color (0xFFF5F5F5 )),
67
+ child: switch (pathName) {
68
+ '/' || ListPage .name => const ListPage (),
69
+ PostPage .name =>
70
+ // Custom "per-page" breakpoints.
71
+ const ResponsiveBreakpoints (breakpoints: [
72
+ Breakpoint (start: 0 , end: 480 , name: MOBILE ),
73
+ Breakpoint (start: 481 , end: 1200 , name: TABLET ),
74
+ Breakpoint (
75
+ start: 1201 , end: double .infinity, name: DESKTOP ),
76
+ ], child: PostPage ()),
77
+ TypographyPage .name => const TypographyPage (),
78
+ _ => const SizedBox .shrink (),
79
+ }),
80
+ dragWithMouse: true );
82
81
});
83
82
}
84
83
}
0 commit comments