1
0
forked from firka/firka

firka: unify grade widget

This commit is contained in:
2026-02-28 23:32:05 +01:00
parent 52f6ebcfd3
commit a9624df915
3 changed files with 77 additions and 105 deletions

View File

@@ -4,14 +4,83 @@ 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.all(8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(str, style: appStyle.fonts.P_14.copyWith(color: gradeColor)),
Text('%', style: appStyle.fonts.P_12.copyWith(color: gradeColor)),
],
),
),
);
}
if (g.numericValue != null) {
gradeColor = getGradeColor(g.numericValue!.toDouble());
}
if (gradeStr == '0') {
return Card(
shadowColor: Colors.transparent,
color: gradeColor.withAlpha(38),
child: Padding(
padding: const EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2),
child: Text(
g.strValue,
style: appStyle.fonts.H_H1.copyWith(
fontSize: 16,
color: gradeColor,
),
),
),
);
}
return _buildNumericCircle(g.numericValue!, gradeColor);
}
Widget _buildNumericCircle(int value, Color gradeColor) {
return Card(
shape: const CircleBorder(),
shadowColor: Colors.transparent,
@@ -19,108 +88,10 @@ class GradeIconWidget extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.only(left: 8, right: 8),
child: Text(
gradeValue.toString(),
value.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),
child: Row(
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),
),
],
),
),
);
}
} else {
if (grade.numericValue != null) {
gradeColor = getGradeColor(grade.numericValue!.toDouble());
}
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),
child: Text(
grade.strValue,
style: appStyle.fonts.H_H1.copyWith(
fontSize: 16,
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: Text(
gradeStr,
style: appStyle.fonts.H_H1.copyWith(
fontSize: 24,
color: gradeColor,
),
),
),
);
}
}
}
}

View File

@@ -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';

View File

@@ -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(