基础组件库
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.
 
 
 
 
 

51 line
1.4 KiB

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