Blame view

lib/pages/shopping/bloc.dart 1.4 KB
4224b3f8   吴启风   feat:支付详情页ui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  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<ShoppingEvent, ShoppingState> {
  
    ProductEntity? _productData;
  
    ProductEntity? get productData => _productData;
  
    PaymentChannel _curPaymentChannel = PaymentChannel.wechatPay;
  
    PaymentChannel get curPaymentChannel => _curPaymentChannel;
  
  
    ShoppingBloc() : super(ShoppingState().init()) {
      //页面初始化时刻
      on<InitEvent>(_init);
      on<ChangePaymentChannelEvent>(_changePaymentChannel);
    }
  
    void _init(InitEvent event, Emitter<ShoppingState> emit) async {
      //处理一些初始化操作,然后刷新界面
      emit(state.clone());
    }
  
    /// 更换支付渠道
    void _changePaymentChannel(ChangePaymentChannelEvent event,
        Emitter<ShoppingState> 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;
  }