ref: firka_card

This commit is contained in:
checkedear
2026-04-13 15:25:48 +02:00
parent 90c334d859
commit fa66d9af14
2 changed files with 94 additions and 81 deletions

View File

@@ -6,26 +6,59 @@ import 'package:firka_common/ui/theme/style.dart';
enum Attach { none, bottom, top }
class FirkaCard extends StatelessWidget {
final List<Widget> left;
final List<Widget> center;
final double padding;
final double? height;
final List<Widget> 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<Widget> left,
double padding = 12,
bool shadow = true,
List<Widget> center = const [],
List<Widget> 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),
),
),
);

View File

@@ -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<Grade> 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)),
),
),
),
],
);
),
],
);
}
}