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

main_page_bloc.dart 1022 B

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839
  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>>>.broadcast();
  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(String skipIdentifier) {
  15. NetUtil.request('/api/v1/mod/${skipIdentifier}', method: NetMethod.GET,
  16. onCache: (data) {
  17. _loadData(data);
  18. }, onSuccess: (data) {
  19. _loadData(data);
  20. });
  21. }
  22. void _loadData(dynamic data) {
  23. Map<String, dynamic> json = Map<String, dynamic>.from(data);
  24. List<dynamic> list = json['mod_list'];
  25. _pageData = list.map((item) {
  26. return Map<String, dynamic>.from(item);
  27. }).toList();
  28. _mainController.add(_pageData);
  29. }
  30. }