Skip to content

Commit c1ef88c

Browse files
committed
(UI) Added a statistics graph
1 parent b1f4da2 commit c1ef88c

File tree

6 files changed

+289
-27
lines changed

6 files changed

+289
-27
lines changed

flutter_01.png

390 KB
Loading

lib/src/pages/badges.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class _PageState extends State<Badges> {
104104
"50 Consecutive Days",
105105
];
106106

107+
// ignore: unused_local_variable
107108
final descriptions = [
108109
"You have registered with TutorMe",
109110
"You have attended 10 consecutive days",

lib/src/pages/home.dart

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import 'dart:typed_data';
44

55
import 'package:flutter/material.dart';
6+
// ignore: import_of_legacy_library_into_null_safe
7+
import 'package:pie_chart/pie_chart.dart';
68
import 'package:provider/provider.dart';
79
import 'package:tutor_me/src/colorpallete.dart';
810
import 'package:tutor_me/src/pages/badges.dart';
@@ -12,6 +14,8 @@ import '../../services/models/globals.dart';
1214
import '../../services/models/users.dart';
1315
import '../../services/services/user_services.dart';
1416
import '../theme/themes.dart';
17+
import '../tutorAndTuteeCollaboration/tuteeGroups/home_tutee_groups.dart';
18+
1519

1620
class Home extends StatefulWidget {
1721
final Globals globals;
@@ -68,19 +72,87 @@ class _HomeState extends State<Home> {
6872
}
6973

7074
getUserType() async {
71-
final type =
72-
await UserServices.getUserType(widget.globals.getUser.getUserTypeID, widget.globals);
75+
final type = await UserServices.getUserType(
76+
widget.globals.getUser.getUserTypeID, widget.globals);
7377

7478
userType = type;
7579

7680
// getConnections();
7781
getTuteeProfileImage();
7882
}
7983

84+
int key = 0;
85+
86+
Map<String, double> dataMap = {
87+
"Meetings": 5,
88+
"Connections": 3,
89+
"Interactions": 2,
90+
"Ratings": 2,
91+
};
92+
93+
List<Color> chartColorList = [
94+
Colors.blue,
95+
colorLightGreen,
96+
Colors.orange,
97+
Colors.yellow,
98+
];
99+
100+
Widget buildChart() {
101+
return PieChart(
102+
key: ValueKey(key),
103+
dataMap: dataMap,
104+
initialAngleInDegree: 0,
105+
animationDuration: const Duration(milliseconds: 3500),
106+
chartType: ChartType.ring,
107+
ringStrokeWidth: 12,
108+
colorList: chartColorList,
109+
chartLegendSpacing: 34,
110+
chartRadius: MediaQuery.of(context).size.width / 4.2,
111+
chartValuesOptions: ChartValuesOptions(
112+
showChartValueBackground: true,
113+
showChartValues: true,
114+
showChartValuesInPercentage: true,
115+
showChartValuesOutside: true,
116+
decimalPlaces: 1,
117+
chartValueStyle: TextStyle(
118+
color: const Color.fromARGB(255, 49, 47, 47),
119+
fontWeight: FontWeight.normal,
120+
fontSize: MediaQuery.of(context).size.width * 0.04,
121+
),
122+
),
123+
// centerText: 'Progress',
124+
legendOptions: LegendOptions(
125+
showLegendsInRow: false,
126+
legendPosition: LegendPosition.right,
127+
showLegends: true,
128+
legendShape: BoxShape.circle,
129+
legendTextStyle: TextStyle(
130+
fontWeight: FontWeight.bold,
131+
color: colorDarkGrey,
132+
fontSize: MediaQuery.of(context).size.width * 0.03),
133+
),
134+
);
135+
}
136+
// List<
137+
138+
// _generateData() {
139+
// var data = [
140+
// Task(
141+
// task: 'Meetings',
142+
// taskValue: 35.8,
143+
// color: const Color(0xff3366cc),
144+
// ),
145+
// Task(task: 'Connections', taskValue: 4, color: colorOrange),
146+
// Task(task: 'Badges', taskValue: 1, color: colorLightGreen),
147+
// Task(task: 'OverAll', taskValue: 32, color: colorBlueTeal),
148+
// ];
149+
// }
150+
80151
@override
81152
void initState() {
82153
super.initState();
83154
getUserType();
155+
// _generateData();
84156
}
85157

86158
Widget buildBody() {
@@ -114,12 +186,6 @@ class _HomeState extends State<Home> {
114186
String name = widget.globals.getUser.getName;
115187
String fullName = name + ' ' + widget.globals.getUser.getLastName;
116188

117-
// FilePickerResult? filePickerResult;
118-
// String? fileName;
119-
// PlatformFile? file;
120-
// bool isUploading = false;
121-
// File? fileToUpload;
122-
123189
return Column(
124190
crossAxisAlignment: CrossAxisAlignment.start,
125191
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -202,11 +268,11 @@ class _HomeState extends State<Home> {
202268
child: Container(
203269
width: screenWidthSize > 800 ? 500 : screenWidthSize * 0.8,
204270
height: screenHeightSize * 0.2,
205-
decoration: const BoxDecoration(
206-
image: DecorationImage(
207-
image: AssetImage("assets/Pictures/progressBar.jpg"),
208-
fit: BoxFit.cover),
209-
borderRadius: BorderRadius.all(Radius.circular(10))),
271+
decoration: BoxDecoration(
272+
// color: Colors.black38,
273+
border: Border.all(color: colorLightGrey.withOpacity(0.6)),
274+
borderRadius: const BorderRadius.all(Radius.circular(10))),
275+
child: buildChart(),
210276
),
211277
),
212278
SizedBox(height: screenHeightSize * 0.02),
@@ -221,7 +287,7 @@ class _HomeState extends State<Home> {
221287
),
222288
SizedBox(width: screenWidthSize * 0.02),
223289
Text(
224-
"New meeting scheduled...",
290+
"How to increase your stats...",
225291
style: TextStyle(fontSize: screenHeightSize * 0.025),
226292
),
227293
],
@@ -247,11 +313,11 @@ class _HomeState extends State<Home> {
247313
),
248314
SizedBox(width: screenWidthSize * 0.02),
249315
Text(
250-
"New meeting scheduled...",
316+
"What do the stats mean ?...",
251317
style: TextStyle(fontSize: screenHeightSize * 0.025),
252318
),
253319
Text(
254-
"more updates",
320+
"more info",
255321
style: TextStyle(color: highlightColor),
256322
overflow: TextOverflow.ellipsis,
257323
),
@@ -296,6 +362,11 @@ class _HomeState extends State<Home> {
296362
//render Tutees Page
297363
} else if (index == 1) {
298364
//render Groups Page
365+
Navigator.push(
366+
context,
367+
MaterialPageRoute(
368+
builder: (context) =>
369+
HomeTuteeGroups(globals: widget.globals)));
299370
} else if (index == 2) {
300371
//render Badges Page
301372
Navigator.of(context).push(MaterialPageRoute(
@@ -391,3 +462,11 @@ class _HomeState extends State<Home> {
391462
);
392463
}
393464
}
465+
466+
class Task {
467+
String task;
468+
double taskValue;
469+
Color color;
470+
471+
Task({required this.task, required this.taskValue, required this.color});
472+
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
// ignore_for_file: file_names
2+
import 'package:flutter/material.dart';
3+
import 'package:tutor_me/services/models/groups.dart';
4+
import 'package:tutor_me/services/services/group_services.dart';
5+
import 'package:tutor_me/services/services/module_services.dart';
6+
import 'package:tutor_me/src/colorpallete.dart';
7+
import '../../../services/models/globals.dart';
8+
import '../../../services/models/modules.dart';
9+
import '../../Groups/tutee_group.dart';
10+
11+
class HomeTuteeGroups extends StatefulWidget {
12+
final Globals globals;
13+
const HomeTuteeGroups({Key? key, required this.globals}) : super(key: key);
14+
15+
@override
16+
State<StatefulWidget> createState() {
17+
return _HomeTuteeGroupsState();
18+
}
19+
}
20+
21+
class _HomeTuteeGroupsState extends State<HomeTuteeGroups> {
22+
String images =
23+
'https://cdn.pixabay.com/photo/2018/09/27/09/22/artificial-intelligence-3706562_960_720.jpg';
24+
25+
bool hasGroups = false;
26+
bool isLoading = true;
27+
28+
List<Groups> groups = List<Groups>.empty();
29+
List<Modules> modules = List<Modules>.empty(growable: true);
30+
final numTuteesForEachGroup = <int>[];
31+
32+
int numOfTutees = 3;
33+
getGroupDetails() async {
34+
final incomingGroups = await GroupServices.getGroupByUserID(
35+
widget.globals.getUser.getId, widget.globals);
36+
groups = incomingGroups;
37+
if (groups.isNotEmpty) {
38+
setState(() {
39+
hasGroups = true;
40+
});
41+
}
42+
43+
for (int k = 0; k < numTuteesForEachGroup.length; k++) {
44+
k.toString() + " 's # tutees " + numTuteesForEachGroup[k].toString();
45+
}
46+
setState(() {
47+
groups = incomingGroups;
48+
numOfTutees = numOfTutees;
49+
});
50+
getGroupModules();
51+
}
52+
53+
getGroupModules() async {
54+
try {
55+
for (int i = 0; i < groups.length; i++) {
56+
final incomingModules = await ModuleServices.getModule(
57+
groups[i].getModuleId, widget.globals);
58+
modules.add(incomingModules);
59+
}
60+
} catch (e) {
61+
const snack = SnackBar(content: Text('Error loading modules'));
62+
ScaffoldMessenger.of(context).showSnackBar(snack);
63+
}
64+
setState(() {
65+
isLoading = false;
66+
});
67+
}
68+
69+
@override
70+
void initState() {
71+
super.initState();
72+
getGroupDetails();
73+
}
74+
75+
@override
76+
Widget build(BuildContext context) {
77+
return DefaultTabController(
78+
length: 3,
79+
child: Scaffold(
80+
appBar: AppBar(
81+
backgroundColor: colorBlueTeal,
82+
title: const Text(' My Groups'),
83+
centerTitle: true,
84+
),
85+
body: Center(
86+
child: isLoading
87+
? const CircularProgressIndicator.adaptive()
88+
: !hasGroups
89+
? Column(
90+
mainAxisAlignment: MainAxisAlignment.center,
91+
children: <Widget>[
92+
Icon(
93+
Icons.people,
94+
size: MediaQuery.of(context).size.height * 0.1,
95+
color: colorOrange,
96+
),
97+
const Text("No Groups Found")
98+
])
99+
: SizedBox(
100+
width: MediaQuery.of(context).size.width * 0.8,
101+
child: Padding(
102+
padding: EdgeInsets.only(
103+
top: MediaQuery.of(context).size.height * 0.04),
104+
child: ListView.separated(
105+
itemBuilder: groupBuilder,
106+
separatorBuilder:
107+
(BuildContext context, index) {
108+
return SizedBox(
109+
height: MediaQuery.of(context).size.height *
110+
0.03,
111+
);
112+
},
113+
itemCount: groups.length))),
114+
),
115+
));
116+
}
117+
118+
Widget groupBuilder(BuildContext context, int i) {
119+
return GestureDetector(
120+
onTap: () {
121+
Navigator.of(context).push(MaterialPageRoute(
122+
builder: (context) => TuteeGroupPage(
123+
globals: widget.globals,
124+
group: groups[i],
125+
numberOfParticipants: numOfTutees,
126+
module: modules[i])));
127+
},
128+
child: Container(
129+
width: MediaQuery.of(context).size.width * 0.8,
130+
height: MediaQuery.of(context).size.height * 0.25,
131+
decoration: BoxDecoration(
132+
color: colorOrange,
133+
borderRadius: BorderRadius.circular(15),
134+
),
135+
child: Column(
136+
crossAxisAlignment: CrossAxisAlignment.stretch,
137+
children: <Widget>[
138+
ClipRRect(
139+
borderRadius: const BorderRadius.only(
140+
topLeft: Radius.circular(8.0),
141+
topRight: Radius.circular(8.0),
142+
),
143+
child: Image.network(
144+
'https://cdn.pixabay.com/photo/2018/09/27/09/22/artificial-intelligence-3706562_960_720.jpg',
145+
height: 100,
146+
fit: BoxFit.fill,
147+
),
148+
),
149+
Row(
150+
children: [
151+
SizedBox(height: MediaQuery.of(context).size.height * 0.04),
152+
Text(" " + modules[i].getCode,
153+
style: TextStyle(
154+
fontSize: MediaQuery.of(context).size.height * 0.03,
155+
color: colorWhite,
156+
fontWeight: FontWeight.bold,
157+
)),
158+
SizedBox(width: MediaQuery.of(context).size.width * 0.110),
159+
const Icon(Icons.circle, size: 7, color: colorLightGreen),
160+
SizedBox(width: MediaQuery.of(context).size.width * 0.03),
161+
Text(
162+
" " + numOfTutees.toString() + " participant(s)",
163+
style: const TextStyle(
164+
color: Colors.white70, fontWeight: FontWeight.bold),
165+
),
166+
],
167+
),
168+
SizedBox(
169+
height: MediaQuery.of(context).size.height * 0.01,
170+
),
171+
Text(
172+
" " + modules[i].getModuleName,
173+
style: TextStyle(
174+
fontSize: MediaQuery.of(context).size.width * 0.05,
175+
color: colorWhite,
176+
),
177+
)
178+
],
179+
),
180+
),
181+
);
182+
}
183+
}

0 commit comments

Comments
 (0)