import 'package:ConversionFlutterDemo/models/convert_bean.dart'; import 'package:ConversionFlutterDemo/models/convert_contain_options_bean.dart'; import 'package:ConversionFlutterDemo/states/convert_provider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; ///Use ‘EventChannel’ to communicate with Android\ios for file conversion. class ConvertFlutter { static const EventChannel _channel = EventChannel('com.compdfkit.conversion.flutter.convert'); void convert(BuildContext context, ConvertBean bean) { _channel.receiveBroadcastStream(bean.getOptions()).listen((event) { Map result = event; String tag = result['dataTag']; int progress = result['progress']; int status = result['status']; context.read().updateStatus(tag, progress, status, null); if (status == convertSuccess || status == convertFail) { context .read() .updateStatus(tag, progress, status, result['outputPath']); ConvertBean nextBean = context.read().getNextConvertBean(); convert(context, nextBean); } }, onDone: () {}, onError: (object) {}); } }