基础组件库
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

57 satır
1.6 KiB

  1. import 'dart:async';
  2. import 'package:bloc/bloc.dart';
  3. import 'package:equatable/equatable.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:zhiying_base_widget/pages/team_page/bloc/team_repository.dart';
  6. import 'package:zhiying_base_widget/pages/team_page/model/team_data_model.dart';
  7. import 'package:zhiying_base_widget/pages/team_page/model/team_style_model.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. part 'team_event.dart';
  10. part 'team_state.dart';
  11. class TeamBloc extends Bloc<TeamEvent, TeamState> {
  12. // TeamBloc() : super(TeamInitial());
  13. TeamRepository repository;
  14. TeamBloc({@required this.repository}) : super(TeamInitial());
  15. @override
  16. Stream<TeamState> mapEventToState(
  17. TeamEvent event,
  18. ) async* {
  19. /// 初始化
  20. if (event is TeamInitEvent) {
  21. yield* _mapInitEventToState(event);
  22. }
  23. }
  24. /// 初始化数据
  25. Stream<TeamState> _mapInitEventToState(TeamInitEvent event) async* {
  26. var cache = await repository.fetchCacheStyleData(event.data);
  27. if (!EmptyUtil.isEmpty(cache)) {
  28. yield TeamLoadedState(styleModel: cache);
  29. }
  30. var resultStyle = await repository.fetchNetStyleData(event.data);
  31. if (!EmptyUtil.isEmpty(resultStyle)) {
  32. yield TeamLoadedState(styleModel: resultStyle);
  33. }
  34. var resultData = await repository.fetchNetData();
  35. if (!EmptyUtil.isEmpty(resultData) && (!EmptyUtil.isEmpty(resultStyle) || !EmptyUtil.isEmpty(cache))) {
  36. yield TeamLoadedState(dataModel: resultData, styleModel: !EmptyUtil.isEmpty(resultStyle) ? resultStyle : cache);
  37. } else {
  38. yield TeamErrorState();
  39. }
  40. }
  41. }