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

37 lines
1004 B

  1. import 'dart:async';
  2. import 'package:zhiying_base_widget/pages/feedback_page/bloc/feedback_repository.dart';
  3. import 'package:zhiying_comm/zhiying_comm.dart';
  4. import 'feedback_event.dart';
  5. import 'feedback_state.dart';
  6. import 'package:flutter_bloc/flutter_bloc.dart';
  7. class FeedbackBloc extends Bloc<FeedbackEvent, FeedbackState> {
  8. // FeedbackBloc() : super(FeedbackInitial());
  9. @override
  10. FeedbackState get initialState => FeedbackInitial();
  11. FeedBackRepository repository;
  12. FeedbackBloc(this.repository);
  13. @override
  14. Stream<FeedbackState> mapEventToState(
  15. FeedbackEvent event,
  16. ) async* {
  17. /// 初始化
  18. if (event is FeedbackInitEvent) {
  19. yield* _mapInitToState(event);
  20. }
  21. }
  22. /// 初始化
  23. Stream<FeedbackState> _mapInitToState(FeedbackInitEvent event) async* {
  24. var result = await repository.fetchData(event.model);
  25. if (!EmptyUtil.isEmpty(result)) {
  26. yield FeedbackLoadedState(model: result);
  27. } else {
  28. yield FeedbackErrorState();
  29. }
  30. }
  31. }