fix: frames
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import '../../../../../core/locator/locator.dart';
|
||||
import '../../../../../core/network/api_provider_imp.dart';
|
||||
import '../../../../../core/theme/frames.dart';
|
||||
import '../../../../../core/theme/ranks.dart';
|
||||
import '../../../domain/entities/frame.dart';
|
||||
|
||||
/// دادهٔ قابهای آواتار از backend (دریافت، خرید، انتخاب).
|
||||
@@ -12,12 +14,34 @@ class FrameApiProvider {
|
||||
throw Exception('frames: ${res.statusCode}');
|
||||
}
|
||||
final list = (res.data['frames'] as List?) ?? const [];
|
||||
return FrameCatalog(
|
||||
frames: list
|
||||
.map((e) => AvatarFrame.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
selected: (res.data['selected'] ?? '') as String,
|
||||
final frames = list
|
||||
.map((e) => AvatarFrame.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList();
|
||||
// کشِ رنگِ قابها را بهروزرسانی کن تا HUD رنگِ درست را از سرور بگیرد.
|
||||
FrameStyles.I.setFromCatalog(
|
||||
frames.map((f) => (id: f.id, c1: f.c1, c2: f.c2)),
|
||||
);
|
||||
// کشِ رنگ/برچسبِ رتبهها هم از همین پاسخ پر میشود.
|
||||
final tiers = (res.data['rank_tiers'] as List?) ?? const [];
|
||||
RankStyles.I.setFromCatalog(
|
||||
tiers.map((e) {
|
||||
final m = Map<String, dynamic>.from(e as Map);
|
||||
return (
|
||||
id: (m['id'] ?? '') as String,
|
||||
label: (m['label'] ?? '') as String,
|
||||
c1: (m['c1'] ?? '') as String,
|
||||
c2: (m['c2'] ?? '') as String,
|
||||
);
|
||||
}),
|
||||
);
|
||||
return FrameCatalog(frames: frames, selected: (res.data['selected'] ?? '') as String);
|
||||
}
|
||||
|
||||
/// کشِ رنگِ قابها را از سرور گرم میکند (best-effort؛ برای رندرِ قابِ دیگران).
|
||||
Future<void> warmCache() async {
|
||||
try {
|
||||
await getFrames();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// خرید؛ null یعنی موفق، وگرنه پیامِ خطای فارسی.
|
||||
|
||||
@@ -4,6 +4,8 @@ class AvatarFrame {
|
||||
final String title;
|
||||
final int priceCoins;
|
||||
final bool vip;
|
||||
final String c1; // رنگِ گرادیان (hex بدونِ #)؛ خالی ⇒ قابِ رتبه
|
||||
final String c2;
|
||||
final bool owned;
|
||||
|
||||
const AvatarFrame({
|
||||
@@ -11,6 +13,8 @@ class AvatarFrame {
|
||||
required this.title,
|
||||
required this.priceCoins,
|
||||
required this.vip,
|
||||
required this.c1,
|
||||
required this.c2,
|
||||
required this.owned,
|
||||
});
|
||||
|
||||
@@ -19,6 +23,8 @@ class AvatarFrame {
|
||||
title: (j['title'] ?? '') as String,
|
||||
priceCoins: (j['price_coins'] ?? 0) as int,
|
||||
vip: (j['vip'] ?? false) as bool,
|
||||
c1: (j['c1'] ?? '') as String,
|
||||
c2: (j['c2'] ?? '') as String,
|
||||
owned: (j['owned'] ?? false) as bool,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user