Update example

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2025-04-30 14:52:41 +02:00
parent 1eab50b0f5
commit 2f18c4213f
2 changed files with 41 additions and 6 deletions
+20 -3
View File
@@ -263,7 +263,14 @@ class _HomeScreenState extends State<HomeScreen> {
); );
}, },
child: Container( 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, width: 20,
height: 20, height: 20,
), ),
@@ -516,12 +523,22 @@ class _HomeScreenState extends State<HomeScreen> {
Arcane.log( Arcane.log(
"Set a color in FavoriteColorService", "Set a color in FavoriteColorService",
metadata: { metadata: {
"color": colors[index].name, "color":
colors[index].name ?? "Unknown",
}, },
); );
}, },
child: Container( 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, width: 20,
height: 20, height: 20,
), ),
@@ -25,8 +25,8 @@ class FavoriteColorService extends ArcaneService {
} }
} }
extension ColorName on MaterialColor { extension MaterialColorName on MaterialColor {
String get name { String? get name {
final double red = double.parse(r.toStringAsFixed(4)); final double red = double.parse(r.toStringAsFixed(4));
final double green = double.parse(g.toStringAsFixed(4)); final double green = double.parse(g.toStringAsFixed(4));
final double blue = double.parse(b.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.6118 && green == 0.1529 && blue == 0.6902) return "indigo";
if (red == 0.4039 && green == 0.2275 && blue == 0.7176) return "violet"; 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;
} }
} }