2024-08-03 13:29:48 +00:00
|
|
|
import 'package:get/get.dart';
|
2024-08-03 17:37:54 +00:00
|
|
|
import 'package:solian/models/pagination.dart';
|
|
|
|
import 'package:solian/models/stickers.dart';
|
|
|
|
import 'package:solian/services.dart';
|
2024-08-03 13:29:48 +00:00
|
|
|
|
|
|
|
class StickerProvider extends GetxController {
|
2024-08-03 17:53:52 +00:00
|
|
|
final RxMap<String, String> aliasImageMapping = RxMap();
|
2024-08-06 10:18:40 +00:00
|
|
|
final RxList<Sticker> availableStickers = RxList.empty(growable: true);
|
2024-08-03 13:29:48 +00:00
|
|
|
|
2024-08-03 17:37:54 +00:00
|
|
|
Future<void> refreshAvailableStickers() async {
|
2024-08-06 17:47:53 +00:00
|
|
|
availableStickers.clear();
|
|
|
|
aliasImageMapping.clear();
|
|
|
|
|
2024-08-03 17:37:54 +00:00
|
|
|
final client = ServiceFinder.configureClient('files');
|
|
|
|
final resp = await client.get(
|
|
|
|
'/stickers/manifest?take=100',
|
|
|
|
);
|
|
|
|
if (resp.statusCode == 200) {
|
|
|
|
final result = PaginationResult.fromJson(resp.body);
|
|
|
|
final out = result.data?.map((e) => StickerPack.fromJson(e)).toList();
|
|
|
|
if (out == null) return;
|
|
|
|
|
|
|
|
for (final pack in out) {
|
|
|
|
for (final sticker in (pack.stickers ?? List<Sticker>.empty())) {
|
|
|
|
sticker.pack = pack;
|
2024-08-06 17:47:53 +00:00
|
|
|
aliasImageMapping[sticker.textPlaceholder.toUpperCase()] =
|
2024-08-06 10:18:40 +00:00
|
|
|
sticker.imageUrl;
|
|
|
|
availableStickers.add(sticker);
|
2024-08-03 17:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-03 17:53:52 +00:00
|
|
|
availableStickers.refresh();
|
2024-08-03 17:37:54 +00:00
|
|
|
}
|
|
|
|
}
|