From d3e30689f09717affbe1883e4cefb29217acf899 Mon Sep 17 00:00:00 2001 From: Armand <4831c0@proton.me> Date: Thu, 11 Sep 2025 21:33:05 +0200 Subject: [PATCH] firka_card: fix dark mode shadow closes #39 --- firka/lib/helpers/ui/firka_card.dart | 134 +++++++++++++------------ firka/lib/helpers/ui/firka_shadow.dart | 41 ++++++++ 2 files changed, 112 insertions(+), 63 deletions(-) create mode 100644 firka/lib/helpers/ui/firka_shadow.dart diff --git a/firka/lib/helpers/ui/firka_card.dart b/firka/lib/helpers/ui/firka_card.dart index 8dbba67..1f11865 100644 --- a/firka/lib/helpers/ui/firka_card.dart +++ b/firka/lib/helpers/ui/firka_card.dart @@ -1,5 +1,7 @@ +import 'package:firka/helpers/ui/firka_shadow.dart'; import 'package:flutter/material.dart'; +import '../../main.dart'; import '../../ui/model/style.dart'; enum Attach { none, bottom, top } @@ -37,29 +39,73 @@ class FirkaCard extends StatelessWidget { return SizedBox( width: MediaQuery.of(context).size.width, height: height, - child: Card( - color: color ?? appStyle.colors.card, - shadowColor: shadow ? null : Colors.transparent, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: 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(attached == Attach.bottom - ? attachedRounding - : defaultRounding)), - ), - child: Padding( - padding: const EdgeInsets.all(12.0), - child: Column( - children: [ - Row( + child: FirkaShadow( + shadow: shadow, + child: Card( + color: color ?? appStyle.colors.card, + shadowColor: + isLightMode.value && shadow ? null : Colors.transparent, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topLeft: 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(attached == Attach.bottom + ? attachedRounding + : defaultRounding)), + ), + child: Padding( + padding: const EdgeInsets.all(12.0), + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row(children: left), + Row(children: center ?? []), + Row(children: right), + ], + ), + extra ?? SizedBox(), + ], + ), + ), + )), + ); + } else { + return SizedBox( + width: MediaQuery.of(context).size.width, + height: height, + child: FirkaShadow( + shadow: shadow, + child: Card( + color: color ?? appStyle.colors.card, + shadowColor: + isLightMode.value && shadow ? null : Colors.transparent, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topLeft: 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(attached == Attach.bottom + ? attachedRounding + : defaultRounding)), + ), + child: Padding( + padding: const EdgeInsets.all(12.0), + child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row(children: left), @@ -67,46 +113,8 @@ class FirkaCard extends StatelessWidget { Row(children: right), ], ), - extra ?? SizedBox(), - ], - ), - ), - ), - ); - } else { - return SizedBox( - width: MediaQuery.of(context).size.width, - height: height, - child: Card( - color: color ?? appStyle.colors.card, - shadowColor: shadow ? null : Colors.transparent, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: 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(attached == Attach.bottom - ? attachedRounding - : defaultRounding)), - ), - child: Padding( - padding: const EdgeInsets.all(12.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row(children: left), - Row(children: center ?? []), - Row(children: right), - ], - ), - ), - ), + ), + )), ); } } diff --git a/firka/lib/helpers/ui/firka_shadow.dart b/firka/lib/helpers/ui/firka_shadow.dart new file mode 100644 index 0000000..f4cf2ad --- /dev/null +++ b/firka/lib/helpers/ui/firka_shadow.dart @@ -0,0 +1,41 @@ +import 'package:firka/main.dart'; +import 'package:flutter/material.dart'; + +import '../../ui/model/style.dart'; + +class FirkaShadow extends StatelessWidget { + final Widget child; + final bool shadow; + + const FirkaShadow({required this.shadow, required this.child, super.key}); + + @override + Widget build(BuildContext context) { + final borderRadius = BorderRadius.circular(8.0); + + final shadowBox = BoxDecoration( + color: Colors.transparent, + shape: BoxShape.rectangle, + boxShadow: [ + BoxShadow( + color: appStyle.colors.shadowColor, + spreadRadius: -4, + blurRadius: 0, + offset: Offset(0, 2)) + ], + borderRadius: BorderRadius.all(Radius.circular(16))); + + if (!shadow) { + return ClipRRect(borderRadius: borderRadius, child: child); + } + + if (isLightMode.value) { + return child; + } else { + return Container( + decoration: shadowBox, + child: ClipRRect(borderRadius: borderRadius, child: child), + ); + } + } +}