-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tab2.dart
104 lines (96 loc) · 2.76 KB
/
Tab2.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
import 'dart:ui';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
class Tab2 extends StatefulWidget {
_Tab2State createState() => _Tab2State();
}
class _Tab2State extends State<Tab2> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
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.cancel),
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 SingleChildScrollView(
child: 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,
),
))),
),
),
),
);
},
),
);
}
}