import 'package:bloc/bloc.dart'; import 'package:wow_english/models/product_entity.dart'; import '../../utils/log_util.dart'; import 'event.dart'; import 'state.dart'; class ShoppingBloc extends Bloc { ProductEntity? _productData; ProductEntity? get productData => _productData; PaymentChannel _curPaymentChannel = PaymentChannel.wechatPay; PaymentChannel get curPaymentChannel => _curPaymentChannel; ShoppingBloc() : super(ShoppingState().init()) { //页面初始化时刻 on(_init); on(_changePaymentChannel); } void _init(InitEvent event, Emitter emit) async { //处理一些初始化操作,然后刷新界面 emit(state.clone()); } /// 更换支付渠道 void _changePaymentChannel(ChangePaymentChannelEvent event, Emitter emitter) async { Log.d("_curPaymentChannel=$_curPaymentChannel, event.paymentChannel=${event.paymentChannel}"); if (_curPaymentChannel != event.paymentChannel) { _curPaymentChannel = event.paymentChannel; emitter(PaymentChannelChangeState()); } } void _gotoPay() { // 跳转到支付页面 } } enum PaymentChannel { wechatPay(1, "微信支付"), aliPay(2, "支付宝支付"); const PaymentChannel(this.payChannelType, this.payChannelName); final int payChannelType; final String payChannelName; }