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

hot_ranking_bloc.dart 1.1 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import 'dart:async';
  2. import 'package:zhiying_comm/util/base_bloc.dart';
  3. import 'package:zhiying_comm/zhiying_comm.dart';
  4. class HotRankingBloc extends BlocBase {
  5. List<Map<String, dynamic>> _pageData = List();
  6. StreamController<List<Map<String, dynamic>>> _dataController =
  7. StreamController<List<Map<String, dynamic>>>();
  8. Stream<List<Map<String, dynamic>>> get outData => _dataController.stream;
  9. @override
  10. void dispose() {
  11. _dataController.close();
  12. _dataController = 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. _dataController.add(_pageData);
  35. }
  36. }