-
Notifications
You must be signed in to change notification settings - Fork 1
/
home_page.dart
192 lines (179 loc) · 4.87 KB
/
home_page.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import 'package:flutter/material.dart';
import 'package:persistent_bottom_bar/persistent_bottom_bar_scaffold.dart';
class HomePage extends StatelessWidget {
final _tab1navigatorKey = GlobalKey<NavigatorState>();
final _tab2navigatorKey = GlobalKey<NavigatorState>();
final _tab3navigatorKey = GlobalKey<NavigatorState>();
@override
Widget build(BuildContext context) {
return PersistentBottomBarScaffold(
items: [
PersistentTabItem(
tab: TabPage1(),
icon: Icons.home,
title: 'Home',
navigatorkey: _tab1navigatorKey,
),
PersistentTabItem(
tab: TabPage2(),
icon: Icons.search,
title: 'Search',
navigatorkey: _tab2navigatorKey,
),
PersistentTabItem(
tab: TabPage3(),
icon: Icons.person,
title: 'Profile',
navigatorkey: _tab3navigatorKey,
),
],
);
}
}
class TabPage1 extends StatelessWidget {
const TabPage1({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
print('TabPage1 build');
return Scaffold(
appBar: AppBar(title: Text('Tab 1')),
body: Container(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Tab 1'),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => Page1('Tab1')));
},
child: Text('Go to page1'))
],
),
),
);
}
}
class TabPage2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
print('TabPage2 build');
return Scaffold(
appBar: AppBar(title: Text('Tab 2')),
body: Container(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Tab 2'),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => Page2('tab2')));
},
child: Text('Go to page2'))
],
),
),
);
}
}
class TabPage3 extends StatelessWidget {
@override
Widget build(BuildContext context) {
print('TabPage3 build');
return Scaffold(
appBar: AppBar(title: Text('Tab 3')),
body: Container(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Tab 3'),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => Page2('tab3')));
},
child: Text('Go to page2'))
],
),
),
);
}
}
class Page1 extends StatelessWidget {
final String inTab;
const Page1(this.inTab);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Page 1')),
body: Container(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('in $inTab Page 1'),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => Page2(inTab)));
},
child: Text('Go to page2'))
],
),
),
);
}
}
class Page2 extends StatelessWidget {
final String inTab;
const Page2(this.inTab);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Page 2')),
body: Container(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('in $inTab Page 2'),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => Page3(inTab)));
},
child: Text('Go to page3'))
],
),
),
);
}
}
class Page3 extends StatelessWidget {
final String inTab;
const Page3(this.inTab);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Page 3')),
body: Container(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('in $inTab Page 3'),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Go back'))
],
),
),
);
}
}