1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 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';
- /// convert_flutter.dart
- ///
- /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- ///
- /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- /// This notice may not be removed from this file.
- ///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<dynamic, dynamic> result = event;
- String tag = result['dataTag'];
- int progress = result['progress'];
- int status = result['status'];
- context.read<ConvertProvider>().updateStatus(tag, progress, status, null);
- if (status == convertSuccess || status == convertFail) {
- print('outPutPath:${result['outputPath']}');
- context
- .read<ConvertProvider>()
- .updateStatus(tag, progress, status, result['outputPath']);
- ConvertBean nextBean =
- context.read<ConvertProvider>().getNextConvertBean();
- convert(context, nextBean);
- }
- }, onDone: () {}, onError: (object) {});
- }
- }
|