forked from firka/firka
firka: unify grade widget
This commit is contained in:
@@ -4,99 +4,70 @@ import 'package:flutter/material.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/components/grade_helpers.dart';
|
||||
|
||||
class GradeIconWidget extends StatelessWidget {
|
||||
final int gradeValue;
|
||||
class GradeWidget extends StatelessWidget {
|
||||
const GradeWidget(this.grade, {super.key})
|
||||
: gradeValue = null,
|
||||
_fromValue = false;
|
||||
|
||||
const GradeIconWidget(this.gradeValue, {super.key});
|
||||
const GradeWidget.gradeValue(int value, {super.key})
|
||||
: grade = null,
|
||||
gradeValue = value,
|
||||
_fromValue = true;
|
||||
|
||||
final Grade? grade;
|
||||
final int? gradeValue;
|
||||
final bool _fromValue;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final gradeColor = getGradeColor(gradeValue.toDouble());
|
||||
if (_fromValue && gradeValue != null) {
|
||||
return _buildNumericCircle(
|
||||
gradeValue!,
|
||||
getGradeColor(gradeValue!.toDouble()),
|
||||
);
|
||||
}
|
||||
|
||||
final g = grade!;
|
||||
Color gradeColor = appStyle.colors.grade1;
|
||||
final gradeStr = g.numericValue?.toString() ?? '0';
|
||||
|
||||
if (g.valueType.name == 'Szazalekos') {
|
||||
if (g.numericValue != null) {
|
||||
gradeColor = getGradeColor(
|
||||
percentageToGrade(g.numericValue!).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
final str = g.strValue.replaceAll('%', '');
|
||||
return Card(
|
||||
shape: const CircleBorder(),
|
||||
shadowColor: Colors.transparent,
|
||||
color: gradeColor.withAlpha(38),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 8, right: 8),
|
||||
child: Text(
|
||||
gradeValue.toString(),
|
||||
style: appStyle.fonts.H_H1.copyWith(fontSize: 24, color: gradeColor),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class GradeWidget extends StatelessWidget {
|
||||
final Grade grade;
|
||||
|
||||
const GradeWidget(this.grade, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Color gradeColor = appStyle.colors.grade1;
|
||||
var gradeStr = grade.numericValue?.toString() ?? "0";
|
||||
double eccentricity = 0;
|
||||
|
||||
if (grade.valueType.name == "Szazalekos") {
|
||||
gradeStr = grade.strValue.replaceAll("%", "");
|
||||
if (grade.numericValue != null) {
|
||||
gradeColor = getGradeColor(
|
||||
percentageToGrade(grade.numericValue!).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
if (grade.numericValue != null && grade.numericValue == 100) {
|
||||
return Card(
|
||||
shape: CircleBorder(eccentricity: eccentricity),
|
||||
shadowColor: Colors.transparent,
|
||||
color: gradeColor.withAlpha(38),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 8, right: 8),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"100", // TODO: Make this curved
|
||||
style: appStyle.fonts.P_14.copyWith(color: gradeColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Card(
|
||||
shape: CircleBorder(eccentricity: eccentricity),
|
||||
shadowColor: Colors.transparent,
|
||||
color: gradeColor.withAlpha(38),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 8, right: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
gradeStr,
|
||||
style: appStyle.fonts.P_14.copyWith(color: gradeColor),
|
||||
),
|
||||
Text(
|
||||
"%",
|
||||
style: appStyle.fonts.P_12.copyWith(color: gradeColor),
|
||||
),
|
||||
Text(str, style: appStyle.fonts.P_14.copyWith(color: gradeColor)),
|
||||
Text('%', style: appStyle.fonts.P_12.copyWith(color: gradeColor)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (grade.numericValue != null) {
|
||||
gradeColor = getGradeColor(grade.numericValue!.toDouble());
|
||||
|
||||
if (g.numericValue != null) {
|
||||
gradeColor = getGradeColor(g.numericValue!.toDouble());
|
||||
}
|
||||
if (gradeStr == "0") {
|
||||
|
||||
if (gradeStr == '0') {
|
||||
return Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: gradeColor.withAlpha(38),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2),
|
||||
padding: const EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2),
|
||||
child: Text(
|
||||
grade.strValue,
|
||||
g.strValue,
|
||||
style: appStyle.fonts.H_H1.copyWith(
|
||||
fontSize: 16,
|
||||
color: gradeColor,
|
||||
@@ -104,23 +75,23 @@ class GradeWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
}
|
||||
|
||||
return _buildNumericCircle(g.numericValue!, gradeColor);
|
||||
}
|
||||
|
||||
Widget _buildNumericCircle(int value, Color gradeColor) {
|
||||
return Card(
|
||||
shape: CircleBorder(eccentricity: eccentricity),
|
||||
shape: const CircleBorder(),
|
||||
shadowColor: Colors.transparent,
|
||||
color: gradeColor.withAlpha(38),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 8, right: 8),
|
||||
padding: const EdgeInsets.only(left: 8, right: 8),
|
||||
child: Text(
|
||||
gradeStr,
|
||||
style: appStyle.fonts.H_H1.copyWith(
|
||||
fontSize: 24,
|
||||
color: gradeColor,
|
||||
),
|
||||
value.toString(),
|
||||
style: appStyle.fonts.H_H1.copyWith(fontSize: 24, color: gradeColor),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:firka/data/models/generic_cache_model.dart';
|
||||
import 'package:firka/data/models/homework_cache_model.dart';
|
||||
|
||||
@@ -92,7 +92,9 @@ class _GradeSummaryBarState extends State<GradeSummaryBar> {
|
||||
SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: FittedBox(child: GradeIconWidget(grade)),
|
||||
child: FittedBox(
|
||||
child: GradeWidget.gradeValue(grade),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
|
||||
Reference in New Issue
Block a user