Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

56 lines
1.3 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/models/gift_item_model.dart';
  3. import 'package:chat/utils/HttpUtil.dart';
  4. import 'package:chat/utils/TokenMgr.dart';
  5. import 'package:dio/dio.dart';
  6. class GiftMgr {
  7. static GiftMgr _instance;
  8. static GiftMgr _getInstance() {
  9. if (_instance == null) {
  10. _instance = GiftMgr._();
  11. }
  12. return _instance;
  13. }
  14. factory GiftMgr() => _getInstance();
  15. GiftMgr._();
  16. static Map<int, String> giftMap = {};
  17. Future<List<GiftItemModel>> getGiftList() async {
  18. Map data = {
  19. "userId": UserData().basicInfo.userId,
  20. };
  21. data['sign'] = TokenMgr().getSign(data);
  22. Response res = await HttpUtil().post('prop/get/list', data: data);
  23. if (res == null) {
  24. return null;
  25. }
  26. Map resData = res.data;
  27. if (resData['code'] == 0) {
  28. //领取成功
  29. List<GiftItemModel> giftList = resData['data'].map<GiftItemModel>((v) {
  30. var model = GiftItemModel.fromJson(v);
  31. updateGiftMap(model);
  32. return model;
  33. }).toList();
  34. return giftList;
  35. }
  36. return null;
  37. }
  38. updateGiftMap(GiftItemModel itemModel) {
  39. giftMap[itemModel.id] = itemModel.name;
  40. }
  41. getGiftName(int id) {
  42. return giftMap[id] ?? '';
  43. }
  44. }