scan_code_handler.dart 657 Bytes
import 'dart:async';
import 'package:appframe/services/dispatcher.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:flutter/material.dart';

import 'package:appframe/bloc/web_cubit.dart';

class ScanCodeHandler extends MessageHandler {
  late WebCubit? _webCubit;

  @override
  Future<dynamic> handleMessage(params) async {
    try {
      final result = await _webCubit!.goScanCode();
      
      // 返回扫码结果
      return result;
    } finally {
      _unfollowCubit();
    }
  }

  @override
  void setCubit(WebCubit cubit) {
    this._webCubit = cubit;
  }

  void _unfollowCubit() {
    this._webCubit = null;
  }
}