convert_flutter.dart 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import 'package:ConversionFlutterDemo/models/convert_bean.dart';
  2. import 'package:ConversionFlutterDemo/models/convert_contain_options_bean.dart';
  3. import 'package:ConversionFlutterDemo/states/convert_provider.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/services.dart';
  6. import 'package:provider/provider.dart';
  7. /// convert_flutter.dart
  8. ///
  9. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  10. ///
  11. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  12. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  13. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  14. /// This notice may not be removed from this file.
  15. ///Use ‘EventChannel’ to communicate with Android\ios for file conversion.
  16. class ConvertFlutter {
  17. static const EventChannel _channel =
  18. EventChannel('com.compdfkit.conversion.flutter.convert');
  19. void convert(BuildContext context, ConvertBean bean) {
  20. _channel.receiveBroadcastStream(bean.getOptions()).listen((event) {
  21. Map<dynamic, dynamic> result = event;
  22. String tag = result['dataTag'];
  23. int progress = result['progress'];
  24. int status = result['status'];
  25. context.read<ConvertProvider>().updateStatus(tag, progress, status, null);
  26. if (status == convertSuccess || status == convertFail) {
  27. print('outPutPath:${result['outputPath']}');
  28. context
  29. .read<ConvertProvider>()
  30. .updateStatus(tag, progress, status, result['outputPath']);
  31. ConvertBean nextBean =
  32. context.read<ConvertProvider>().getNextConvertBean();
  33. convert(context, nextBean);
  34. }
  35. }, onDone: () {}, onError: (object) {});
  36. }
  37. }