choose_video_handler.dart 1.27 KB
import 'package:appframe/bloc/web_cubit.dart';
import 'package:appframe/services/dispatcher.dart';

class ChooseVideoHandler extends MessageHandler {
  late WebCubit? _webCubit;
  late String? _message;

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

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

  @override
  void setMessage(String message) {
    this._message = message;
  }

  @override
  Future<dynamic> handleMessage(params) async {
    try {
      if (params is! Map<String, dynamic>) {
        throw Exception('参数错误');
      }
      var sourceType = params['sourceType'] as String;
      if (sourceType != 'album' && sourceType != 'camera') {
        throw Exception('参数错误');
      }

      int count = 1;
      if (params.containsKey('count')) {
        count = params['count'] as int;
        if (count < 1 || count > 9) {
          throw Exception('参数错误');
        }
      }

      int maxDuration = 60;
      if (params.containsKey('maxDuration')) {
        maxDuration = params['maxDuration'] as int;
        if (maxDuration < 1 || maxDuration > 600) {
          throw Exception('参数错误');
        }
      }

      _webCubit!.setChooseVideoCmdFlag(true, _message!);
    } finally {
      _unfollowCubit();
    }
  }
}