1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import 'package:ConversionFlutterDemo/convert_flutter.dart';
- import 'package:ConversionFlutterDemo/models/convert_contain_options_bean.dart';
- import 'package:ConversionFlutterDemo/models/convert_type.dart';
- import 'package:flutter/material.dart';
- import '../models/convert_bean.dart';
- import 'package:path/path.dart';
- /// convert_provider.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.
- class ConvertProvider extends ChangeNotifier {
- final List<ConvertBean> _items = [];
- List<ConvertBean> get items => _items;
- void addConvertData(BuildContext context, ConvertType convertType,
- ConvertOptionsBean options, List<String?> filePath) {
- var hasConvertingData = false;
- var list = _items.where((element) => element.status == convertConverting);
- if(list.isNotEmpty){
- hasConvertingData = true;
- }
- for (var i = 0; i < filePath.length; i++) {
- String? path = filePath[i];
- if (path != null) {
- ConvertBean convertBean = ConvertBean(
- tag:
- '${path}_${convertType}_${DateTime.now().millisecondsSinceEpoch}',
- filePath: path,
- fileName: basenameWithoutExtension(path),
- convertType: convertType.name,
- status: convertConverting,
- progress: 0,
- options: options);
- _items.add(convertBean);
- }
- }
- if(!hasConvertingData){
- ConvertFlutter().convert(context, getNextConvertBean());
- }
- notifyListeners();
- }
- void updateStatus(String tag, int progress, int status, String? outputPath) {
- ConvertBean bean = _items.firstWhere((element) => element.tag == tag);
- bean
- ..status = status
- ..progress = progress
- ..outputPath = outputPath;
- notifyListeners();
- }
- ConvertBean getNextConvertBean() {
- return _items.firstWhere((element) => element.status == convertConverting);
- }
- }
|