From 2f18c4213f730216de054b1c4c88c1932ae5af11 Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Wed, 30 Apr 2025 14:52:41 +0200 Subject: [PATCH] Update example Signed-off-by: Hans Kokx --- example/lib/main.dart | 23 +++++++++++++++--- .../lib/services/favorite_color_service.dart | 24 ++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index c55028b..d892e26 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -263,7 +263,14 @@ class _HomeScreenState extends State { ); }, child: Container( - color: colors[index], + decoration: BoxDecoration( + color: colors[index], + border: Arcane.theme.currentTheme + .colorScheme.primary.name == + colors[index].name + ? Border.all(width: 2) + : null, + ), width: 20, height: 20, ), @@ -516,12 +523,22 @@ class _HomeScreenState extends State { Arcane.log( "Set a color in FavoriteColorService", metadata: { - "color": colors[index].name, + "color": + colors[index].name ?? "Unknown", }, ); }, child: Container( - color: colors[index], + decoration: BoxDecoration( + color: colors[index], + border: ArcaneService.ofType< + FavoriteColorService>( + context, + )?.myFavoriteColor?.name == + colors[index].name + ? Border.all(width: 2) + : null, + ), width: 20, height: 20, ), diff --git a/example/lib/services/favorite_color_service.dart b/example/lib/services/favorite_color_service.dart index 53b8fba..c9f2193 100644 --- a/example/lib/services/favorite_color_service.dart +++ b/example/lib/services/favorite_color_service.dart @@ -25,8 +25,8 @@ class FavoriteColorService extends ArcaneService { } } -extension ColorName on MaterialColor { - String get name { +extension MaterialColorName on MaterialColor { + String? get name { final double red = double.parse(r.toStringAsFixed(4)); final double green = double.parse(g.toStringAsFixed(4)); final double blue = double.parse(b.toStringAsFixed(4)); @@ -38,6 +38,24 @@ extension ColorName on MaterialColor { if (red == 0.6118 && green == 0.1529 && blue == 0.6902) return "indigo"; if (red == 0.4039 && green == 0.2275 && blue == 0.7176) return "violet"; - return ""; + return null; + } +} + +extension ColorName on Color { + String? get name { + final double red = double.parse(r.toStringAsFixed(4)); + final double green = double.parse(g.toStringAsFixed(4)); + final double blue = double.parse(b.toStringAsFixed(4)); + + if (red == 0.5647 && green == 0.2902 && blue == 0.2588) return "red"; + if (red == 0.5216 && green == 0.3255 && blue == 0.0941) return "orange"; + if (red == 0.4078 && green == 0.3725 && blue == 0.0706) return "yellow"; + if (red == 0.2314 && green == 0.4118 && blue == 0.2235) return "green"; + if (red == 0.2118 && green == 0.3804 && blue == 0.5569) return "blue"; + if (red == 0.4824 && green == 0.3059 && blue == 0.498) return "indigo"; + if (red == 0.4078 && green == 0.3294 && blue == 0.5569) return "violet"; + + return null; } }