From fa66d9af14753a5a8be0594db7c32b8845a49cf4 Mon Sep 17 00:00:00 2001 From: checkedear <271323618+checkedear@users.noreply.github.com> Date: Mon, 13 Apr 2026 15:25:48 +0200 Subject: [PATCH] ref: firka_card --- .../lib/ui/components/firka_card.dart | 85 ++++++++++-------- .../lib/ui/shared/grade_small_card.dart | 90 ++++++++++--------- 2 files changed, 94 insertions(+), 81 deletions(-) diff --git a/firka_common/lib/ui/components/firka_card.dart b/firka_common/lib/ui/components/firka_card.dart index 3968f25..96bcfbc 100644 --- a/firka_common/lib/ui/components/firka_card.dart +++ b/firka_common/lib/ui/components/firka_card.dart @@ -6,26 +6,59 @@ import 'package:firka_common/ui/theme/style.dart'; enum Attach { none, bottom, top } class FirkaCard extends StatelessWidget { - final List left; - final List center; + final double padding; final double? height; - final List right; final bool shadow; - final Widget? extra; - final Attach? attached; + final Attach attached; final Color? color; final bool? isLightMode; + final Widget child; - const FirkaCard({ - required this.left, + factory FirkaCard({ + required List left, + double padding = 12, + bool shadow = true, + List center = const [], + List right = const [], + Widget? extra, + Attach attached = Attach.none, + Color? color, + double? height, + bool? isLightMode, + }) { + final leftRow = Row(children: left); + + final alignedRow = right.isEmpty && center.isEmpty + ? leftRow + : Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + leftRow, + Row(children: center), + Row(children: right), + ], + ); + return FirkaCard.single( + padding: padding, + attached: attached, + color: color, + height: height, + shadow: shadow, + isLightMode: isLightMode, + child: extra == null + ? alignedRow + : Column(children: [alignedRow, extra!]), + ); + } + + const FirkaCard.single({ + this.padding = 12, this.shadow = true, - this.center = const [], - this.right = const [], - this.extra, this.attached = Attach.none, this.color, this.height, this.isLightMode, + required this.child, super.key, }); @@ -36,19 +69,6 @@ class FirkaCard extends StatelessWidget { final isLight = isLightMode ?? Theme.of(context).brightness == Brightness.light; - final leftRow = Row(children: this.left); - - final alignedRow = this.right.isEmpty && this.center.isEmpty - ? leftRow - : Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - leftRow, - Row(children: this.center), - Row(children: this.right), - ], - ); - return SizedBox( width: MediaQuery.of(context).size.width, height: height, @@ -59,27 +79,16 @@ class FirkaCard extends StatelessWidget { color: color ?? appStyle.colors.card, shadowColor: isLight && shadow ? null : Colors.transparent, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: Radius.circular( + borderRadius: BorderRadius.vertical( + top: Radius.circular( attached == Attach.top ? attachedRounding : defaultRounding, ), - topRight: Radius.circular( - attached == Attach.top ? attachedRounding : defaultRounding, - ), - bottomLeft: Radius.circular( - attached == Attach.bottom ? attachedRounding : defaultRounding, - ), - bottomRight: Radius.circular( + bottom: Radius.circular( attached == Attach.bottom ? attachedRounding : defaultRounding, ), ), ), - child: Padding( - padding: const EdgeInsets.all(12.0), - child: this.extra == null - ? alignedRow - : Column(children: [alignedRow, this.extra!]), - ), + child: Padding(padding: EdgeInsets.all(this.padding), child: child), ), ), ); diff --git a/firka_common/lib/ui/shared/grade_small_card.dart b/firka_common/lib/ui/shared/grade_small_card.dart index f18252e..d4b0f51 100644 --- a/firka_common/lib/ui/shared/grade_small_card.dart +++ b/firka_common/lib/ui/shared/grade_small_card.dart @@ -6,55 +6,59 @@ import 'package:firka_common/ui/components/grade_helpers.dart'; import 'package:firka_common/ui/shared/class_icon.dart'; import 'package:firka_common/ui/theme/style.dart'; -class GradeSmallCard extends FirkaCard { +import '../../firka_common.dart'; + +class GradeSmallCard extends StatelessWidget { final List grades; final Subject subject; - GradeSmallCard(this.grades, this.subject, {super.key}) - : super( - left: [ - ClassIconWidget( - uid: subject.uid, - className: subject.name, - category: subject.category.name!, - color: appStyle.colors.accent, - ), - const SizedBox(width: 4), - SizedBox( - width: 200, - child: Text( - subject.name, - style: appStyle.fonts.B_16SB.apply( - color: appStyle.colors.textPrimary, - ), + GradeSmallCard(this.grades, this.subject, {super.key}); + + @override + Widget build(BuildContext context) { + return FirkaCard( + left: [ + ClassIconWidget( + uid: subject.uid, + className: subject.name, + category: subject.category.name!, + color: appStyle.colors.accent, + ), + const SizedBox(width: 4), + SizedBox( + width: 200, + child: Text( + subject.name, + style: appStyle.fonts.B_16SB.apply( + color: appStyle.colors.textPrimary, ), ), - ], - right: [ - grades.getAverageBySubject(subject).isNaN - ? const SizedBox() - : Card( - shadowColor: Colors.transparent, - color: getGradeColor( - grades.getAverageBySubject(subject), - ).withAlpha(38), - child: Padding( - padding: const EdgeInsets.only( - left: 8, - right: 8, - top: 4, - bottom: 4, - ), - child: Text( - grades.getAverageBySubject(subject).toStringAsFixed(2), - style: appStyle.fonts.B_16SB.apply( - color: getGradeColor( - grades.getAverageBySubject(subject), - ), - ), + ), + ], + right: [ + grades.getAverageBySubject(subject).isNaN + ? const SizedBox() + : Card( + shadowColor: Colors.transparent, + color: getGradeColor( + grades.getAverageBySubject(subject), + ).withAlpha(38), + child: Padding( + padding: const EdgeInsets.only( + left: 8, + right: 8, + top: 4, + bottom: 4, + ), + child: Text( + grades.getAverageBySubject(subject).toStringAsFixed(2), + style: appStyle.fonts.B_16SB.apply( + color: getGradeColor(grades.getAverageBySubject(subject)), ), ), ), - ], - ); + ), + ], + ); + } }