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

45 lines
1.1 KiB

  1. import 'dart:async';
  2. import 'package:zhiying_comm/util/base_bloc.dart';
  3. import 'package:zhiying_comm/zhiying_comm.dart';
  4. class MainPageBloc extends BlocBase {
  5. List<Map<String, dynamic>> _pageData = List();
  6. StreamController<List<Map<String, dynamic>>> _mainController =
  7. StreamController<List<Map<String, dynamic>>>();
  8. Stream<List<Map<String, dynamic>>> get outData => _mainController.stream;
  9. @override
  10. void dispose() {
  11. _mainController.close();
  12. _mainController = null;
  13. }
  14. void loadData(int id) {
  15. NetUtil.request('/api/v1/mod',
  16. method: NetMethod.POST,
  17. params: Map<String, dynamic>.from({
  18. 'ids': [id]
  19. }), onCache: (data) {
  20. _loadData(id, data);
  21. }, onSuccess: (data) {
  22. _loadData(id, data);
  23. });
  24. }
  25. void _loadData(int id, dynamic data) {
  26. String key = id.toString();
  27. Map<String, dynamic> json = Map<String, dynamic>.from(data);
  28. if (json.containsKey(key)) {
  29. List<dynamic> list = json[key];
  30. _pageData = list.map((item) {
  31. return Map<String, dynamic>.from(item);
  32. }).toList();
  33. }
  34. _mainController.add(_pageData);
  35. }
  36. }