基础组件库
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

invited_friends_bloc.dart 1.8 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'dart:async';
  2. import 'dart:convert' as convert;
  3. import 'package:zhiying_base_widget/pages/invited_friends/models/invite_friend_data_model.dart';
  4. import 'package:zhiying_base_widget/pages/invited_friends/models/invited_friends_model.dart';
  5. import 'package:zhiying_comm/util/base_bloc.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. class InvitedFriendshBloc extends BlocBase {
  8. InvitedFriendsModel _model;
  9. StreamController<InvitedFriendsModel> _dataController =
  10. StreamController<InvitedFriendsModel>();
  11. Stream<InvitedFriendsModel> get outData => _dataController.stream;
  12. @override
  13. void dispose() {
  14. _dataController.close();
  15. _dataController = null;
  16. }
  17. void loadData(String skipIdentifier) async {
  18. Map<String, dynamic> data =
  19. await NetUtil.post('/api/v1/user/invitefriend', method: NetMethod.GET);
  20. InvitedFriendsDataModel dataModel = InvitedFriendsDataModel.fromJson(
  21. Map<String, dynamic>.from(data['data']));
  22. NetUtil.request('/api/v1/mod/${skipIdentifier.toString()}',
  23. method: NetMethod.GET, onCache: (data) {}, onSuccess: (data) {
  24. _model = _loadData(data);
  25. _model?.dataModel = dataModel;
  26. _dataController.add(_model);
  27. });
  28. }
  29. InvitedFriendsModel _loadData(dynamic data) {
  30. try {
  31. Map<String, dynamic> json = Map<String, dynamic>.from(data);
  32. if (json == null || json.length == 0) {
  33. return null;
  34. }
  35. List mods = json['mod_list'];
  36. if (mods.first != null) {
  37. json = Map<String, dynamic>.from(mods.first);
  38. String d = json['data'];
  39. Map<String, dynamic> da =
  40. Map<String, dynamic>.from(convert.jsonDecode(d));
  41. return InvitedFriendsModel.fromJson(da);
  42. }
  43. } catch (err) {
  44. Logger.error(err);
  45. }
  46. return null;
  47. }
  48. }