fix: frames
This commit is contained in:
+34
-19
@@ -1,24 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_theme.dart';
|
||||
/// کشِ رنگِ قابها که از سرور میآید (id → گرادیان). با هر بار خواندنِ کاتالوگِ
|
||||
/// قابها پر میشود؛ هیچ رنگی سمتِ کلاینت hardcode نیست (تا کش پر نشود، null).
|
||||
class FrameStyles {
|
||||
FrameStyles._();
|
||||
static final FrameStyles I = FrameStyles._();
|
||||
|
||||
/// گرادیانِ هر قابِ آواتار (کازمتیک). شناسهها با کاتالوگِ سرور جور است.
|
||||
/// null یعنی «بدون قابِ اختصاصی» ⇒ از قابِ رتبه استفاده شود.
|
||||
List<Color>? frameGradient(String id) {
|
||||
switch (id) {
|
||||
case 'gold':
|
||||
return const [Color(0xFFF3D27A), AppColors.goldDark];
|
||||
case 'fire':
|
||||
return const [Color(0xFFFF9A3C), Color(0xFFB81D2A)];
|
||||
case 'emerald':
|
||||
return const [Color(0xFF7BEAA5), Color(0xFF1B7A4A)];
|
||||
case 'ocean':
|
||||
return const [Color(0xFF8FD3F0), Color(0xFF1E5FA8)];
|
||||
case 'rose':
|
||||
return const [Color(0xFFF7A8C4), Color(0xFFA83060)];
|
||||
case 'royal':
|
||||
return const [Color(0xFFCE9BEA), Color(0xFF6A2FA0)];
|
||||
default: // none / '' / ناشناخته
|
||||
return null;
|
||||
final Map<String, List<Color>> _cache = {};
|
||||
|
||||
/// کشِ رنگها را از کاتالوگِ سرور پر میکند. هر آیتم باید id و دو رنگِ hex بدهد.
|
||||
void setFromCatalog(Iterable<({String id, String c1, String c2})> frames) {
|
||||
for (final f in frames) {
|
||||
final g = _parse(f.c1, f.c2);
|
||||
if (g != null) _cache[f.id] = g;
|
||||
}
|
||||
}
|
||||
|
||||
List<Color>? gradient(String id) {
|
||||
if (id.isEmpty || id == 'none') return null;
|
||||
return _cache[id];
|
||||
}
|
||||
|
||||
static List<Color>? _parse(String c1, String c2) {
|
||||
final a = _hex(c1), b = _hex(c2);
|
||||
if (a == null || b == null) return null;
|
||||
return [a, b];
|
||||
}
|
||||
|
||||
static Color? _hex(String s) {
|
||||
s = s.trim().replaceAll('#', '');
|
||||
if (s.length != 6) return null;
|
||||
final v = int.tryParse(s, radix: 16);
|
||||
return v == null ? null : Color(0xFF000000 | v);
|
||||
}
|
||||
}
|
||||
|
||||
/// گرادیانِ قابِ آواتار (از کشِ سرور). null ⇒ قابِ رتبه.
|
||||
List<Color>? frameGradient(String id) => FrameStyles.I.gradient(id);
|
||||
|
||||
Reference in New Issue
Block a user