214 lines
4.7 KiB
Dart
214 lines
4.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:miaoji_zhang/shared/widgets/app_icons.dart';
|
|
|
|
class CategoryColorMeta {
|
|
final String key;
|
|
final String label;
|
|
final Color background;
|
|
final Color foreground;
|
|
|
|
const CategoryColorMeta({
|
|
required this.key,
|
|
required this.label,
|
|
required this.background,
|
|
required this.foreground,
|
|
});
|
|
}
|
|
|
|
const categoryColorCatalog = <CategoryColorMeta>[
|
|
CategoryColorMeta(
|
|
key: 'mint',
|
|
label: '薄荷',
|
|
background: Color(0xFFE3F7F0),
|
|
foreground: Color(0xFF008E69),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'teal',
|
|
label: '青绿',
|
|
background: Color(0xFFE1F3F1),
|
|
foreground: Color(0xFF087F72),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'aqua',
|
|
label: '水绿',
|
|
background: Color(0xFFE4F6F5),
|
|
foreground: Color(0xFF168C87),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'cyan',
|
|
label: '青蓝',
|
|
background: Color(0xFFE3F4F7),
|
|
foreground: Color(0xFF187F91),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'sky',
|
|
label: '天蓝',
|
|
background: Color(0xFFE7F2FA),
|
|
foreground: Color(0xFF327EAD),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'blue',
|
|
label: '蓝色',
|
|
background: Color(0xFFE8EFFB),
|
|
foreground: Color(0xFF416FAE),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'navy',
|
|
label: '海军蓝',
|
|
background: Color(0xFFE8ECF3),
|
|
foreground: Color(0xFF425A7B),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'indigo',
|
|
label: '靛蓝',
|
|
background: Color(0xFFEBEDFA),
|
|
foreground: Color(0xFF5864B1),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'violet',
|
|
label: '紫罗兰',
|
|
background: Color(0xFFF0EBF8),
|
|
foreground: Color(0xFF7656A8),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'plum',
|
|
label: '梅紫',
|
|
background: Color(0xFFF5EAF2),
|
|
foreground: Color(0xFF94547E),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'orchid',
|
|
label: '兰紫',
|
|
background: Color(0xFFF6EAF4),
|
|
foreground: Color(0xFFA45291),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'rose',
|
|
label: '玫瑰',
|
|
background: Color(0xFFF9E9EE),
|
|
foreground: Color(0xFFB94E6B),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'coral',
|
|
label: '珊瑚',
|
|
background: Color(0xFFFBEAE6),
|
|
foreground: Color(0xFFC45B49),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'red',
|
|
label: '朱红',
|
|
background: Color(0xFFFBE9E8),
|
|
foreground: Color(0xFFC4473F),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'orange',
|
|
label: '橙色',
|
|
background: Color(0xFFFCEDE2),
|
|
foreground: Color(0xFFBE681F),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'amber',
|
|
label: '琥珀',
|
|
background: Color(0xFFFAF0DB),
|
|
foreground: Color(0xFFA66B0E),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'peach',
|
|
label: '桃色',
|
|
background: Color(0xFFFBEDE6),
|
|
foreground: Color(0xFFB96B45),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'sand',
|
|
label: '沙金',
|
|
background: Color(0xFFF5F0E4),
|
|
foreground: Color(0xFF8C7442),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'lime',
|
|
label: '青柠',
|
|
background: Color(0xFFF0F5E2),
|
|
foreground: Color(0xFF71852D),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'olive',
|
|
label: '橄榄',
|
|
background: Color(0xFFEEF0E3),
|
|
foreground: Color(0xFF68723C),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'forest',
|
|
label: '森林',
|
|
background: Color(0xFFE6F1E9),
|
|
foreground: Color(0xFF39764A),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'slate',
|
|
label: '石板',
|
|
background: Color(0xFFEBEFF0),
|
|
foreground: Color(0xFF5F7074),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'cocoa',
|
|
label: '可可',
|
|
background: Color(0xFFF1ECE8),
|
|
foreground: Color(0xFF796154),
|
|
),
|
|
CategoryColorMeta(
|
|
key: 'graphite',
|
|
label: '石墨',
|
|
background: Color(0xFFEDEEEE),
|
|
foreground: Color(0xFF5D6261),
|
|
),
|
|
];
|
|
|
|
CategoryColorMeta categoryColorMeta(String? key) =>
|
|
categoryColorCatalog.firstWhere(
|
|
(item) => item.key == key,
|
|
orElse: () => categoryColorCatalog.first,
|
|
);
|
|
|
|
(Color bg, Color fg) categoryColors(String? colorKey) {
|
|
final meta = categoryColorMeta(colorKey);
|
|
return (meta.background, meta.foreground);
|
|
}
|
|
|
|
class CategoryIconBox extends StatelessWidget {
|
|
final String iconKey;
|
|
final String? colorKey;
|
|
final double size;
|
|
|
|
const CategoryIconBox({
|
|
super.key,
|
|
required this.iconKey,
|
|
this.colorKey,
|
|
this.size = 36,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final (bg, fg) = categoryColors(colorKey);
|
|
return Container(
|
|
width: size,
|
|
height: size,
|
|
decoration: BoxDecoration(
|
|
color: bg,
|
|
borderRadius: BorderRadius.circular(size * 0.3),
|
|
),
|
|
child: Center(
|
|
child: AppIcons.byKey(iconKey, size: size * 0.5, color: fg),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget categoryIconSvg(
|
|
String key, {
|
|
double size = 24,
|
|
Color? color,
|
|
String? colorKey,
|
|
}) {
|
|
final (_, fg) = categoryColors(colorKey);
|
|
return AppIcons.byKey(key, size: size, color: color ?? fg);
|
|
}
|