From 636d9cd1d0e1dc7847f06b390dd8e405fef951e1 Mon Sep 17 00:00:00 2001 From: Alexandru Mariuti Date: Thu, 23 Jan 2025 11:13:47 +0100 Subject: [PATCH] refactor: order policy option theme (#265) --- CHANGELOG.md | 1 + lib/src/components/select.dart | 2 +- lib/src/theme/components/option.dart | 15 +++++++++++++-- lib/src/theme/components/select.dart | 13 ++----------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0228274d..9d48b201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - **FIX**: Improve `ShadAvatar` (thanks to @mickey35vn). - **FIX**: Locale not handled in `ShadCalendar` and `ShadDatePicker`. +- **REFACTOR**: Remove `optionsOrderPolicy` from `ShadSelectTheme` and move it to `ShadOptionTheme` with the name `orderPolicy`. ## 0.18.2 diff --git a/lib/src/components/select.dart b/lib/src/components/select.dart index 76945da2..6f000803 100644 --- a/lib/src/components/select.dart +++ b/lib/src/components/select.dart @@ -1026,7 +1026,7 @@ class _ShadOptionState extends State> { widget.radius ?? theme.optionTheme.radius ?? theme.radius; final effectiveOrderPolicy = widget.orderPolicy ?? - theme.selectTheme.optionsOrderPolicy ?? + theme.optionTheme.orderPolicy ?? const WidgetOrderPolicy.linear(); final effectiveSelectedIcon = widget.selectedIcon ?? diff --git a/lib/src/theme/components/option.dart b/lib/src/theme/components/option.dart index 69239bd6..84cb5022 100644 --- a/lib/src/theme/components/option.dart +++ b/lib/src/theme/components/option.dart @@ -1,4 +1,5 @@ import 'package:flutter/widgets.dart'; +import 'package:shadcn_ui/src/utils/extensions/order_policy.dart'; @immutable class ShadOptionTheme { @@ -7,6 +8,7 @@ class ShadOptionTheme { this.hoveredBackgroundColor, this.padding, this.radius, + this.orderPolicy, }); final bool merge; @@ -15,6 +17,9 @@ class ShadOptionTheme { final EdgeInsets? padding; final BorderRadius? radius; + /// {@macro ShadOption.orderPolicy} + final WidgetOrderPolicy? orderPolicy; + static ShadOptionTheme lerp( ShadOptionTheme a, ShadOptionTheme b, @@ -27,6 +32,7 @@ class ShadOptionTheme { Color.lerp(a.hoveredBackgroundColor, b.hoveredBackgroundColor, t), padding: EdgeInsets.lerp(a.padding, b.padding, t), radius: BorderRadius.lerp(a.radius, b.radius, t), + orderPolicy: t < 0.5 ? a.orderPolicy : b.orderPolicy, ); } @@ -35,6 +41,7 @@ class ShadOptionTheme { Color? hoveredBackgroundColor, EdgeInsets? padding, BorderRadius? radius, + WidgetOrderPolicy? orderPolicy, }) { return ShadOptionTheme( merge: merge ?? this.merge, @@ -42,6 +49,7 @@ class ShadOptionTheme { hoveredBackgroundColor ?? this.hoveredBackgroundColor, padding: padding ?? this.padding, radius: radius ?? this.radius, + orderPolicy: orderPolicy ?? this.orderPolicy, ); } @@ -52,6 +60,7 @@ class ShadOptionTheme { hoveredBackgroundColor: other.hoveredBackgroundColor, padding: other.padding, radius: other.radius, + orderPolicy: other.orderPolicy, ); } @@ -63,7 +72,8 @@ class ShadOptionTheme { other.merge == merge && other.hoveredBackgroundColor == hoveredBackgroundColor && other.padding == padding && - other.radius == radius; + other.radius == radius && + other.orderPolicy == orderPolicy; } @override @@ -71,6 +81,7 @@ class ShadOptionTheme { return merge.hashCode ^ hoveredBackgroundColor.hashCode ^ padding.hashCode ^ - radius.hashCode; + radius.hashCode ^ + orderPolicy.hashCode; } } diff --git a/lib/src/theme/components/select.dart b/lib/src/theme/components/select.dart index 22facdc0..b5770a32 100644 --- a/lib/src/theme/components/select.dart +++ b/lib/src/theme/components/select.dart @@ -27,7 +27,6 @@ class ShadSelectTheme { this.effects, this.shadows, this.filter, - this.optionsOrderPolicy, }); final bool merge; @@ -52,9 +51,6 @@ class ShadSelectTheme { /// {@macro popover.shadows} final List? shadows; - /// {@macro ShadOption.orderPolicy} - final WidgetOrderPolicy? optionsOrderPolicy; - static ShadSelectTheme lerp( ShadSelectTheme a, ShadSelectTheme b, @@ -78,7 +74,6 @@ class ShadSelectTheme { clearSearchOnClose: t < 0.5 ? a.clearSearchOnClose : b.clearSearchOnClose, effects: t < 0.5 ? a.effects : b.effects, shadows: t < 0.5 ? a.shadows : b.shadows, - optionsOrderPolicy: t < .5 ? a.optionsOrderPolicy : b.optionsOrderPolicy, ); } @@ -120,7 +115,6 @@ class ShadSelectTheme { effects: effects ?? this.effects, shadows: shadows ?? this.shadows, filter: filter ?? this.filter, - optionsOrderPolicy: optionsOrderPolicy ?? this.optionsOrderPolicy, ); } @@ -142,7 +136,6 @@ class ShadSelectTheme { effects: other.effects, shadows: other.shadows, filter: other.filter, - optionsOrderPolicy: other.optionsOrderPolicy, ); } @@ -165,8 +158,7 @@ class ShadSelectTheme { other.clearSearchOnClose == clearSearchOnClose && other.effects == effects && other.shadows == shadows && - other.filter == filter && - other.optionsOrderPolicy == optionsOrderPolicy; + other.filter == filter; } @override @@ -185,7 +177,6 @@ class ShadSelectTheme { clearSearchOnClose.hashCode ^ effects.hashCode ^ shadows.hashCode ^ - filter.hashCode ^ - optionsOrderPolicy.hashCode; + filter.hashCode; } }