/
main.dart
119 lines (107 loc) · 3.04 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import 'package:flutter/material.dart';
import 'package:plus_router/plus_router.dart';
void main() {
runApp(MyApp());
}
List<PlusRoute> routes = [
PlusRoute(
path: "/",
builder: (state, args) => HomePage(routerState: state)
),
PlusRoute(
path: "/home/list",
builder: (state, args) => WelcomePage(routerState: state)
),
PlusRoute(
path: "/home/list/:id",
builder: (state, args) => HomeDetailPage(routerState: state, args: args)
)
];
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Demo Route',
theme: ThemeData(
primarySwatch: Colors.blue,
),
// routeInformationParser: PlusRouteInformationParser(newRoutes,
// initialRoute: "/home" // Custom initialRoute
// ),
routeInformationParser: PlusRouteInformationParser(routes),
// routerDelegate: PlusRouterDelegate(routes,
// loadPage: CustomLoadingPage()
// )
routerDelegate: PlusRouterDelegate(routes)
);
}
}
class HomePage extends StatelessWidget {
final PlusRouterState routerState;
HomePage({ Key? key, required this.routerState }) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Column(
children: [
Container(child: Text("Home Page")),
Container(
child: ElevatedButton(
onPressed: () {
this.routerState.navigateByUrl("/home/list");
},
child: Text("Click"),
)
)
],
)),
);
}
}
class WelcomePage extends StatelessWidget {
final PlusRouterState routerState;
const WelcomePage({ Key? key, required this.routerState }) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Column(
children: [
Container(child: Text("Welcome Page")),
Container(
child: ElevatedButton(
onPressed: () {
this.routerState.navigateByUrl("/home/list/100");
},
child: Text("Click"),
)
)
],
)),
);
}
}
class HomeDetailPage extends StatelessWidget {
final PlusRouterState routerState;
final Map<String, dynamic> args;
const HomeDetailPage({ Key? key, required this.routerState, required this.args }) : super(key: key);
@override
Widget build(BuildContext context) {
String arg = args["id"] ?? "None";
return Scaffold(
body: Center(child: Column(
children: [
Container(child: Text("Detail Page $arg")),
Container(
child: ElevatedButton(
onPressed: () {
this.routerState.back();
},
child: Text("Click"),
)
)
],
)),
);
}
}