import 'dart:async';
import 'dart:math';

import 'package:bloc/bloc.dart';
import 'package:zhiying_base_widget/widgets/goods_details/coupon/bloc/counpon_repository.dart';
import 'bloc.dart';

class CounponBloc extends Bloc<CounponEvent, CounponState> {
  @override
  CounponState get initialState => CounponInitial();

  CounponRepository repository;

  CounponBloc({this.repository});

  @override
  Stream<CounponState> mapEventToState(
    CounponEvent event,
  ) async* {
    if (event is CounponInitEvent) {
      yield* _mapInitEnvetTostate(event);
    }
  }

  /// 获取数据
  Stream<CounponState> _mapInitEnvetTostate(CounponInitEvent event) async* {
    var result = await repository.fetchParentData(event);
    yield CounponLoadedState(model: result);
  }
}
