From 81697d8eac7ef1731659836227883e99b25d510c Mon Sep 17 00:00:00 2001 From: Matthias Ngeo Date: Mon, 15 Jul 2024 21:07:47 +0800 Subject: [PATCH] Make radius configurable --- .../src/widgets/calendar/day/day_picker.dart | 6 +++++ .../src/widgets/calendar/shared/entry.dart | 24 ++++++++++++++----- .../widgets/calendar/year_month_picker.dart | 2 ++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/forui/lib/src/widgets/calendar/day/day_picker.dart b/forui/lib/src/widgets/calendar/day/day_picker.dart index c92e06491..aa72f84b2 100644 --- a/forui/lib/src/widgets/calendar/day/day_picker.dart +++ b/forui/lib/src/widgets/calendar/day/day_picker.dart @@ -213,10 +213,12 @@ final class FCalendarDayPickerStyle with Diagnosticable { selectedStyle: FCalendarEntryStyle( backgroundColor: colorScheme.primaryForeground, textStyle: mutedTextStyle, + radius: const Radius.circular(4), ), unselectedStyle: FCalendarEntryStyle( backgroundColor: colorScheme.background, textStyle: mutedTextStyle, + radius: const Radius.circular(4), ), ); @@ -227,22 +229,26 @@ final class FCalendarDayPickerStyle with Diagnosticable { selectedStyle: FCalendarEntryStyle( backgroundColor: colorScheme.foreground, textStyle: typography.sm.copyWith(color: colorScheme.background, fontWeight: FontWeight.w500), + radius: const Radius.circular(4), ), unselectedStyle: FCalendarEntryStyle( backgroundColor: colorScheme.background, textStyle: textStyle, focusedBackgroundColor: colorScheme.secondary, + radius: const Radius.circular(4), ), ), enclosing: FCalendarDayStyle( selectedStyle: FCalendarEntryStyle( backgroundColor: colorScheme.primaryForeground, textStyle: mutedTextStyle, + radius: const Radius.circular(4), ), unselectedStyle: FCalendarEntryStyle( backgroundColor: colorScheme.background, textStyle: mutedTextStyle, focusedBackgroundColor: colorScheme.primaryForeground, + radius: const Radius.circular(4), ), ), ), diff --git a/forui/lib/src/widgets/calendar/shared/entry.dart b/forui/lib/src/widgets/calendar/shared/entry.dart index 7d75c0ad5..e937562eb 100644 --- a/forui/lib/src/widgets/calendar/shared/entry.dart +++ b/forui/lib/src/widgets/calendar/shared/entry.dart @@ -38,8 +38,8 @@ abstract class Entry extends StatelessWidget { Widget builder(BuildContext context, bool focused, Widget? child) => _Content( style: entryStyle, borderRadius: BorderRadius.horizontal( - left: selected(date.yesterday) ? Radius.zero : const Radius.circular(4), - right: selected(date.tomorrow) ? Radius.zero : const Radius.circular(4), + left: selected(date.yesterday) ? Radius.zero : entryStyle.radius, + right: selected(date.tomorrow) ? Radius.zero : entryStyle.radius, ), text: '${date.day}', // TODO: localization focused: focused, @@ -76,7 +76,7 @@ abstract class Entry extends StatelessWidget { // ignore: avoid_positional_boolean_parameters Widget builder(BuildContext context, bool focused, Widget? child) => _Content( style: entryStyle, - borderRadius: BorderRadius.circular(8), + borderRadius: BorderRadius.all(entryStyle.radius), text: format(date), focused: focused, current: current, @@ -221,10 +221,14 @@ final class FCalendarEntryStyle with Diagnosticable { /// The focused day's text style. Defaults to [textStyle]. final TextStyle focusedTextStyle; + /// The entry border's radius. Defaults to `Radius.circular(4)`. + final Radius radius; + /// Creates a [FCalendarEntryStyle]. FCalendarEntryStyle({ required this.backgroundColor, required this.textStyle, + required this.radius, Color? focusedBackgroundColor, TextStyle? focusedTextStyle, }) : focusedBackgroundColor = focusedBackgroundColor ?? backgroundColor, @@ -250,12 +254,14 @@ final class FCalendarEntryStyle with Diagnosticable { TextStyle? textStyle, Color? focusedBackgroundColor, TextStyle? focusedTextStyle, + Radius? radius, }) => FCalendarEntryStyle( backgroundColor: backgroundColor ?? this.backgroundColor, textStyle: textStyle ?? this.textStyle, focusedBackgroundColor: focusedBackgroundColor ?? this.focusedBackgroundColor, focusedTextStyle: focusedTextStyle ?? this.focusedTextStyle, + radius: radius ?? this.radius, ); @override @@ -265,7 +271,8 @@ final class FCalendarEntryStyle with Diagnosticable { ..add(ColorProperty('backgroundColor', backgroundColor)) ..add(DiagnosticsProperty('textStyle', textStyle)) ..add(ColorProperty('focusedBackgroundColor', focusedBackgroundColor)) - ..add(DiagnosticsProperty('focusedTextStyle', focusedTextStyle)); + ..add(DiagnosticsProperty('focusedTextStyle', focusedTextStyle)) + ..add(DiagnosticsProperty('radius', radius)); } @override @@ -276,9 +283,14 @@ final class FCalendarEntryStyle with Diagnosticable { backgroundColor == other.backgroundColor && textStyle == other.textStyle && focusedBackgroundColor == other.focusedBackgroundColor && - focusedTextStyle == other.focusedTextStyle; + focusedTextStyle == other.focusedTextStyle && + radius == other.radius; @override int get hashCode => - backgroundColor.hashCode ^ textStyle.hashCode ^ focusedBackgroundColor.hashCode ^ focusedTextStyle.hashCode; + backgroundColor.hashCode ^ + textStyle.hashCode ^ + focusedBackgroundColor.hashCode ^ + focusedTextStyle.hashCode ^ + radius.hashCode; } diff --git a/forui/lib/src/widgets/calendar/year_month_picker.dart b/forui/lib/src/widgets/calendar/year_month_picker.dart index 6581eb6da..7b1da364e 100644 --- a/forui/lib/src/widgets/calendar/year_month_picker.dart +++ b/forui/lib/src/widgets/calendar/year_month_picker.dart @@ -93,11 +93,13 @@ final class FCalendarYearMonthPickerStyle with Diagnosticable { backgroundColor: colorScheme.background, textStyle: typography.sm.copyWith(color: colorScheme.foreground, fontWeight: FontWeight.w500), focusedBackgroundColor: colorScheme.secondary, + radius: const Radius.circular(8), ), disabledStyle: FCalendarEntryStyle( backgroundColor: colorScheme.background, textStyle: typography.sm .copyWith(color: colorScheme.mutedForeground.withOpacity(0.5), fontWeight: FontWeight.w500), + radius: const Radius.circular(8), ), );