From 98e98984521cc1f9ff3cd0cfff44c9adbc91d264 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Thu, 1 Aug 2024 11:00:50 -0400 Subject: [PATCH] fix: breakpoint utility merge exception (#421) --- .../src/theme/tokens/breakpoints_token.dart | 3 ++ .../on_breakpoint_util.dart | 2 +- .../context_variant_util/on_util.dart | 1 + .../on_breakpoint_util_test.dart | 36 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/mix/lib/src/theme/tokens/breakpoints_token.dart b/packages/mix/lib/src/theme/tokens/breakpoints_token.dart index 1ea4b0ae8..dcad98970 100644 --- a/packages/mix/lib/src/theme/tokens/breakpoints_token.dart +++ b/packages/mix/lib/src/theme/tokens/breakpoints_token.dart @@ -31,6 +31,9 @@ class Breakpoint { bool matches(Size size) { return size.width >= minWidth && size.width <= maxWidth; } + + @override + String toString() => 'breakpoint_${minWidth}_$maxWidth)'; } /// A token representing a breakpoint. diff --git a/packages/mix/lib/src/variants/context_variant_util/on_breakpoint_util.dart b/packages/mix/lib/src/variants/context_variant_util/on_breakpoint_util.dart index d89ddaede..be3c0c084 100644 --- a/packages/mix/lib/src/variants/context_variant_util/on_breakpoint_util.dart +++ b/packages/mix/lib/src/variants/context_variant_util/on_breakpoint_util.dart @@ -60,7 +60,7 @@ class OnBreakpointTokenVariant extends MediaQueryContextVariant { } @override - Object get mergeKey => '$runtimeType.$token'; + Object get mergeKey => '$runtimeType.${token.name}'; /// The properties used for equality comparison. /// diff --git a/packages/mix/lib/src/variants/context_variant_util/on_util.dart b/packages/mix/lib/src/variants/context_variant_util/on_util.dart index 9b0dd8d51..4cfedc687 100644 --- a/packages/mix/lib/src/variants/context_variant_util/on_util.dart +++ b/packages/mix/lib/src/variants/context_variant_util/on_util.dart @@ -19,6 +19,7 @@ class OnContextVariantUtility { late final large = const OnBreakpointTokenVariant(BreakpointToken.large); late final breakpoint = OnBreakPointVariant.new; + late final breakpointToken = OnBreakpointTokenVariant.new; late final light = const OnBrightnessVariant(Brightness.light); late final dark = const OnBrightnessVariant(Brightness.dark); diff --git a/packages/mix/test/src/variants/context_variant_util/on_breakpoint_util_test.dart b/packages/mix/test/src/variants/context_variant_util/on_breakpoint_util_test.dart index 1757a56df..f9d8a941e 100644 --- a/packages/mix/test/src/variants/context_variant_util/on_breakpoint_util_test.dart +++ b/packages/mix/test/src/variants/context_variant_util/on_breakpoint_util_test.dart @@ -93,6 +93,22 @@ void main() { addTearDown(tester.view.resetPhysicalSize); }); + + // Test merge + test('OnBreakpointTokenVariant mergeKey', () { + final style = Style( + VariantAttribute( + const OnBreakpointTokenVariant(BreakpointToken.small), + Style(), + ), + VariantAttribute( + const OnBreakpointTokenVariant(BreakpointToken.medium), + Style(), + ), + ); + + expect(style.values.length, 2); + }); }); group('OnBreakpoint Variant', () { testWidgets('OnBreakPointVariant', (tester) async { @@ -155,6 +171,26 @@ void main() { addTearDown(tester.view.resetPhysicalSize); }); + // Test merge + test('OnBreakPointVariant mergeKey', () { + final style = Style( + VariantAttribute( + const OnBreakPointVariant( + Breakpoint(maxWidth: 100, minWidth: 50), + ), + Style(), + ), + VariantAttribute( + const OnBreakPointVariant( + Breakpoint(maxWidth: 200, minWidth: 50), + ), + Style(), + ), + ); + + expect(style.values.length, 2); + }); + test('OnBreakPoint equality', () { const breakpoint1 = OnBreakPointVariant( Breakpoint(maxWidth: 100, minWidth: 50),