From a9624df915b502d700233878e46d054eb213aea0 Mon Sep 17 00:00:00 2001 From: Armand <4831c0@proton.me> Date: Sat, 28 Feb 2026 23:32:05 +0100 Subject: [PATCH] firka: unify grade widget --- firka/lib/ui/components/grade.dart | 177 ++++++++---------- .../ui/phone/screens/debug/debug_screen.dart | 1 - .../ui/phone/widgets/grade_summary_bar.dart | 4 +- 3 files changed, 77 insertions(+), 105 deletions(-) diff --git a/firka/lib/ui/components/grade.dart b/firka/lib/ui/components/grade.dart index 8458176a..2f2922e5 100644 --- a/firka/lib/ui/components/grade.dart +++ b/firka/lib/ui/components/grade.dart @@ -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, - ), - ), - ), - ); - } - } - } -} diff --git a/firka/lib/ui/phone/screens/debug/debug_screen.dart b/firka/lib/ui/phone/screens/debug/debug_screen.dart index 10ab5ed0..e339e177 100644 --- a/firka/lib/ui/phone/screens/debug/debug_screen.dart +++ b/firka/lib/ui/phone/screens/debug/debug_screen.dart @@ -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'; diff --git a/firka/lib/ui/phone/widgets/grade_summary_bar.dart b/firka/lib/ui/phone/widgets/grade_summary_bar.dart index 42c43ead..b1f82234 100644 --- a/firka/lib/ui/phone/widgets/grade_summary_bar.dart +++ b/firka/lib/ui/phone/widgets/grade_summary_bar.dart @@ -92,7 +92,9 @@ class _GradeSummaryBarState extends State { SizedBox( width: 32, height: 32, - child: FittedBox(child: GradeIconWidget(grade)), + child: FittedBox( + child: GradeWidget.gradeValue(grade), + ), ), const SizedBox(width: 4), Text(