-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTab1.dart
242 lines (226 loc) · 6.96 KB
/
Tab1.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
class Tab1 extends StatefulWidget {
_Tab1State createState() => _Tab1State();
}
class _Tab1State extends State<Tab1> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
child: ElevatedButton(
child: Text('PAGE 2', style: TextStyle(color: Colors.black)),
onPressed: () {
setState(() {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => Page2()));
});
},
),
),
));
}
}
class Page2 extends StatefulWidget {
_Page2State createState() => _Page2State();
}
class _Page2State extends State<Page2> with SingleTickerProviderStateMixin {
late TabController _tabController;
@override
void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this, initialIndex: 0);
_tabController.addListener(_handleTabChange);
}
@override
void dispose() {
_tabController.removeListener(_handleTabChange);
_tabController.dispose();
super.dispose();
}
void _goToTab2() {
setState(() {
_tabController.index = 1; // Switch to Tab 2
});
}
void _goToPage3() {
setState(() {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => Page3())); // Switch to Tab 2
});
}
void _handleTabChange() {
setState(() {});
}
Widget build(BuildContext context) {
return DefaultTabController(
length: 3, // Number of tabs
child: Scaffold(
appBar: AppBar(
title: Text(
'PAGE 2',
style: TextStyle(color: Colors.white),
),
leading: IconButton(
icon: Icon(Icons.arrow_back), // Change the icon to a simple "<"
onPressed: () {
Navigator.pop(context);
},
color: Colors.white,
),
backgroundColor: Color(0xff070707),
centerTitle: true,
),
bottomNavigationBar: Container(
decoration: BoxDecoration(
color: Colors.grey[200], // Background colour of the tab bar
borderRadius:
BorderRadius.circular(10.0), // Adjust border radius as needed
),
child: TabBar(
indicator: BoxDecoration(
borderRadius:
BorderRadius.circular(10.0), // Adjust border radius as needed
color: Colors.black, // Colour of the selected tab indicator
),
indicatorColor: Colors.transparent,
labelColor: Colors.white,
unselectedLabelColor: Colors.black,
controller: _tabController,
tabs: [
Tab(
child: Align(
alignment: Alignment.center,
child: Container(
width: double
.infinity, // Make the container fill the tab space
height: 40.0, // Adjust height as needed
child: Center(
child: Text(
'TAB 1',
textAlign: TextAlign.center,
),
),
),
),
),
Tab(
child: Align(
alignment: Alignment.center,
child: Container(
width: double
.infinity, // Make the container fill the tab space
height: 40.0, // Adjust height as needed
child: Center(
child: Text(
'TAB 2',
textAlign: TextAlign.center,
),
),
),
),
),
Tab(
child: Align(
alignment: Alignment.center,
child: Container(
width: double
.infinity, // Make the container fill the tab space
height: 40.0, // Adjust height as needed
child: Center(
child: Text(
'TAB 3',
textAlign: TextAlign.center,
),
),
),
),
),
],
),
),
body: Center(
child: ElevatedButton(
child: Text('PAGE 3', style: TextStyle(color: Colors.black)),
onPressed: () {
setState(() {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => Page3()));
});
},
),
),
),
);
}
}
class Page3 extends StatefulWidget {
@override
_Page3State createState() => _Page3State();
}
class _Page3State extends State<Page3> {
List<dynamic> _data = [];
@override
void initState() {
super.initState();
_loadJsonData();
}
Future<void> _loadJsonData() async {
final String jsonString =
await rootBundle.loadString('lib/assets/data.json');
setState(() {
_data = json.decode(jsonString);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'PAGE 3',
style: TextStyle(color: Colors.white),
),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context);
},
color: Colors.white,
),
backgroundColor: Color(0xff0c0c0c),
centerTitle: true,
),
body: ListView.builder(
itemCount: _data.length,
itemBuilder: (context, index) {
final item = _data[index];
return Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
padding: EdgeInsets.all(10.0), // Adjust padding as needed
decoration: BoxDecoration(
color: Color(0xff6fb7f1),
borderRadius: BorderRadius.circular(
5.0), // Adjust border radius as needed
),
child: Center(
child: ListTile(
title: Center(
child: Text(
item['name'],
style: TextStyle(
color: Colors.black, // Text colour
fontSize: 16.0, // Text size
fontWeight: FontWeight.bold,
),
))),
),
),
);
},
),
);
}
}