-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy path38.flutter_go_router_basics.dart
121 lines (114 loc) · 3.56 KB
/
38.flutter_go_router_basics.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
120
121
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:ig_posts/season_2/63.transperant_design_pattern.dart';
import 'package:ig_posts/utils/colors.dart';
final GoRouter router = GoRouter(
routes: <RouteBase>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) {
return const HomeView();
},
routes: <RouteBase>[
GoRoute(
path: 'details_1',
builder: (BuildContext context, GoRouterState state) {
return const Detail1View();
},
),
GoRoute(
path: 'details_2',
builder: (BuildContext context, GoRouterState state) {
return const Detail2View();
},
),
],
),
],
);
class HomeView extends StatelessWidget {
const HomeView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(title: "Flutter Go Router"),
floatingActionButton: ActionChip(
onPressed: () {
context.go("/details_1");
},
backgroundColor: KConstantColors.bgColorFaint,
label: Text("Go tot detail 1",
style: KConstantTextstyles.light(fontSize: 12))),
backgroundColor: KConstantColors.bgColor,
body: Center(
child:
Text("Home View", style: KConstantTextstyles.bold(fontSize: 30))),
);
}
}
class Detail1View extends StatelessWidget {
const Detail1View({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(title: "Flutter Go Router"),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ActionChip(
onPressed: () {
context.go("/details_2");
},
backgroundColor: KConstantColors.redColor,
label: Text("Go tot detail 2",
style: KConstantTextstyles.light(fontSize: 12))),
SizedBox(height: 10),
ActionChip(
onPressed: () {
context.go("/");
},
backgroundColor: KConstantColors.redColor,
label: Text("Go to home",
style: KConstantTextstyles.light(fontSize: 12))),
],
),
backgroundColor: KConstantColors.bgColor,
body: Center(
child: Text("Detail 1 View",
style: KConstantTextstyles.bold(fontSize: 30))),
);
}
}
class Detail2View extends StatelessWidget {
const Detail2View({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(title: "Flutter Go Router"),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ActionChip(
onPressed: () {
context.go("/details_1");
},
backgroundColor: KConstantColors.redColor,
label: Text("Go tot detail 1",
style: KConstantTextstyles.light(fontSize: 12))),
SizedBox(height: 10),
ActionChip(
onPressed: () {
context.go("/");
},
backgroundColor: KConstantColors.redColor,
label: Text("Go to home",
style: KConstantTextstyles.light(fontSize: 12))),
],
),
backgroundColor: KConstantColors.blueColor,
body: Center(
child: Text("Detail 2 View",
style: KConstantTextstyles.bold(fontSize: 30))),
);
}
}