基础组件库
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 lines
1.3 KiB

  1. import 'dart:async';
  2. import 'package:zhiying_base_widget/pages/main_page/model/background_model.dart';
  3. import 'package:zhiying_comm/util/base_bloc.dart';
  4. import 'package:zhiying_comm/zhiying_comm.dart';
  5. import 'dart:convert' as Con;
  6. class MainPageBloc extends BlocBase {
  7. List<Map<String, dynamic>> _pageData = List();
  8. StreamController<List<Map<String, dynamic>>> _mainController =
  9. StreamController<List<Map<String, dynamic>>>.broadcast();
  10. Stream<List<Map<String, dynamic>>> get outData => _mainController.stream;
  11. BackgroundModel backgroundModel;
  12. @override
  13. void dispose() {
  14. _mainController.close();
  15. _mainController = null;
  16. }
  17. void loadData(String skipIdentifier) {
  18. print("加载mainPage"+skipIdentifier);
  19. NetUtil.request('/api/v1/mod/${skipIdentifier}', method: NetMethod.GET,
  20. onCache: (data) {
  21. _loadData(data);
  22. }, onSuccess: (data) {
  23. _loadData(data);
  24. });
  25. }
  26. void _loadData(dynamic data) {
  27. Map<String, dynamic> json = Map<String, dynamic>.from(data);
  28. List<dynamic> list = json['mod_list'];
  29. _pageData = list.map((item) {
  30. return Map<String, dynamic>.from(item);
  31. }).toList();
  32. try{
  33. backgroundModel=BackgroundModel.fromJson(Con.json.decode(json['out_data']));
  34. }catch(e,s){
  35. print(e);
  36. print(s);
  37. }
  38. _mainController.add(_pageData);
  39. }
  40. }