Skip to content

Commit 9ec27da

Browse files
Add color radiant on progress bar (#153)
* Add color radiant on progress bar * Order imports * Fix tests * update goldens Co-authored-by: Camille Brulotte <> Co-authored-by: Samuel Montambault <mont.samuel@outlook.com>
1 parent 72953cc commit 9ec27da

File tree

5 files changed

+91
-16
lines changed

5 files changed

+91
-16
lines changed

ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ PODS:
1616
- Firebase/Analytics (= 8.0.0)
1717
- firebase_core
1818
- Flutter
19-
- firebase_core (1.2.0):
19+
- firebase_core (1.3.0):
2020
- Firebase/CoreOnly (= 8.0.0)
2121
- Flutter
2222
- firebase_crashlytics (2.0.4):
@@ -230,7 +230,7 @@ SPEC CHECKSUMS:
230230
connectivity: c4130b2985d4ef6fd26f9702e886bd5260681467
231231
Firebase: 73c3e3b216ec1ecbc54d2ffdd4670c65c749edb1
232232
firebase_analytics: 221d3bc4e8f1b5144a4bd4cc6b33790ee51bd543
233-
firebase_core: e4d3efb030a2b2021819f8faa538bb23deb46695
233+
firebase_core: cda81ae37eda6df2bc2d16027fda527987c4bd33
234234
firebase_crashlytics: 4f3ce855ce6116de954cde34f88003df8ed9de4a
235235
FirebaseAnalytics: dcb92c7c9ef4fa7ffac276e8f87bd4fc8c97f1b8
236236
FirebaseCore: 3f09591d51292843e2a46f18358d60bf4e996255

lib/ui/widgets/grade_circular_progress.dart

Lines changed: 88 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
import 'package:flutter/material.dart';
33
import 'package:percent_indicator/percent_indicator.dart';
44

5+
// UTILS
6+
import 'package:notredame/ui/utils/app_theme.dart';
7+
58
// OTHERS
69
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
710

8-
class GradeCircularProgress extends StatelessWidget {
11+
class GradeCircularProgress extends StatefulWidget {
912
final bool completed;
1013
final String finalGrade;
1114
final double studentGrade;
@@ -20,48 +23,120 @@ class GradeCircularProgress extends StatelessWidget {
2023
this.averageGrade})
2124
: super(key: key);
2225

26+
@override
27+
_GradeCircularProgressState createState() => _GradeCircularProgressState();
28+
}
29+
30+
class _GradeCircularProgressState extends State<GradeCircularProgress>
31+
with TickerProviderStateMixin {
32+
AnimationController _controller;
33+
Animation<Color> animation;
34+
35+
@override
36+
void initState() {
37+
super.initState();
38+
39+
_controller = AnimationController(
40+
duration: const Duration(milliseconds: 1100),
41+
vsync: this,
42+
);
43+
44+
_controller.forward();
45+
46+
animation = ColorTween(
47+
begin: AppTheme.gradeFailureMin,
48+
end: gradePercentageColor(widget.studentGrade ?? 0.0),
49+
).animate(_controller)
50+
..addListener(() {
51+
setState(() {});
52+
});
53+
}
54+
55+
@override
56+
void dispose() {
57+
_controller.dispose();
58+
super.dispose();
59+
}
60+
2361
@override
2462
Widget build(BuildContext context) {
2563
return CircularPercentIndicator(
2664
animation: true,
2765
animationDuration: 1100,
28-
radius: 100 * ratio,
29-
lineWidth: 8.0 * ratio,
30-
percent: completed ? getGradeInDecimals(studentGrade ?? 0.0) : 0,
66+
radius: 100 * widget.ratio,
67+
lineWidth: 8.0 * widget.ratio,
68+
percent:
69+
widget.completed ? getGradeInDecimals(widget.studentGrade ?? 0.0) : 0,
3170
circularStrokeCap: CircularStrokeCap.round,
3271
center: CircularPercentIndicator(
3372
animation: true,
3473
animationDuration: 700,
35-
radius: 80 * ratio,
36-
lineWidth: 8.0 * ratio,
37-
percent: completed ? getGradeInDecimals(averageGrade ?? 0.0) : 0,
74+
radius: 80 * widget.ratio,
75+
lineWidth: 8.0 * widget.ratio,
76+
percent: widget.completed
77+
? getGradeInDecimals(widget.averageGrade ?? 0.0)
78+
: 0,
3879
circularStrokeCap: CircularStrokeCap.round,
3980
center: Text(
4081
getGrade(context),
4182
style: TextStyle(
4283
color: Theme.of(context).brightness == Brightness.light
4384
? Colors.black
4485
: Colors.white,
45-
fontSize: 22 * ratio),
86+
fontSize: 22 * widget.ratio),
4687
),
4788
progressColor: Colors.red,
4889
),
49-
progressColor: Colors.green,
90+
progressColor: animation.value,
5091
);
5192
}
5293

5394
double getGradeInDecimals(double grade) => grade / 100;
5495

5596
String getGrade(BuildContext context) {
56-
if (finalGrade != null) {
57-
return finalGrade;
97+
if (widget.finalGrade != null) {
98+
return widget.finalGrade;
5899
}
59100

60-
if (studentGrade != null) {
101+
if (widget.studentGrade != null) {
61102
return AppIntl.of(context)
62-
.grades_grade_in_percentage(studentGrade.round());
103+
.grades_grade_in_percentage(widget.studentGrade.round());
63104
}
64105

65106
return AppIntl.of(context).grades_not_available;
66107
}
108+
109+
Color gradePercentageColor(double gradePercentage) {
110+
const double passingGrade = 50.0;
111+
const double minGoodGrade = 80.0;
112+
const double maxGrade = 100.0;
113+
114+
Color startColor;
115+
Color endColor;
116+
double colorProportion = gradePercentage;
117+
118+
if (gradePercentage >= 0 && gradePercentage <= passingGrade) {
119+
startColor = AppTheme.gradeFailureMin;
120+
endColor = AppTheme.gradeFailureMax;
121+
colorProportion /= passingGrade;
122+
} else if (gradePercentage > passingGrade &&
123+
gradePercentage <= minGoodGrade) {
124+
startColor = AppTheme.gradePassing;
125+
endColor = AppTheme.gradeGoodMin;
126+
colorProportion -= passingGrade;
127+
colorProportion /= minGoodGrade - passingGrade;
128+
} else {
129+
startColor = AppTheme.gradeGoodMin;
130+
endColor = AppTheme.gradeGoodMax;
131+
132+
if (colorProportion >= maxGrade) {
133+
colorProportion = 1;
134+
} else {
135+
colorProportion -= minGoodGrade;
136+
colorProportion /= maxGrade - minGoodGrade;
137+
}
138+
}
139+
140+
return Color.lerp(startColor, endColor, colorProportion);
141+
}
67142
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1515
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
1616
# Read more about iOS versioning at
1717
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18-
version: 4.0.3+1
18+
version: 4.0.4+1
1919

2020
environment:
2121
sdk: ">=2.10.0 <3.0.0"
-70 Bytes
Loading
-70 Bytes
Loading

0 commit comments

Comments
 (0)