Explorar el Código

ConversionFlutter - 修复部分iphone设备无法打开转档文件Bug

liuxiaolong hace 2 años
padre
commit
83dbf5003e

+ 2 - 1
ios/Runner/ConverFilePlugin.swift

@@ -33,12 +33,13 @@ class SwiftStreamHandler: NSObject,FlutterStreamHandler {
         let filePath = convertData[params_file_path] ?? "";
         let convertType = convertData[params_convert_type]!;
         let dataTag = String(convertData[params_data_tag]!);
+        let fileName = convertData[params_file_name] ?? "";
         let queue = DispatchQueue(label: "com.compdfkit.conversion.flutter")
         queue.async {
 
          self.util = ConvertUtil()
          let options = self.util?.getConvertOptions(withArguments: arguments)
-         self.util?.convert(options: options!, filePath: filePath, convertType: convertType) { progress, status, outputPath in
+         self.util?.convert(options: options!, filePath: filePath,fileName: fileName, convertType: convertType) { progress, status, outputPath in
              events(["progress": progress, params_data_tag: dataTag, "status" : status, "outputPath" : outputPath])
          }
             

+ 1 - 1
ios/Runner/ConvertDefine.swift

@@ -14,7 +14,7 @@ import Foundation
 
 let params_convert_type:String = "convertType";
 let params_file_path:String = "filePath";
-let params_file_name:String = "file_name";
+let params_file_name:String = "fileName";
 let params_data_tag:String = "dataTag";
 let params_contain_images:String = "containImages";
 let params_contain_annotations:String = "containAnnotations";

+ 12 - 11
ios/Runner/ConvertUtil.swift

@@ -117,7 +117,7 @@ class ConvertUtil : NSObject,CPDFConverterDelegate{
     
 
     
-     func convert(options :CPDFConvertOptions, filePath:String, convertType : String, onProgress : @escaping (_ progress : Int, _ status : Int, _ outputPath : String?) -> Void) {
+    func convert(options :CPDFConvertOptions, filePath:String,fileName : String, convertType : String, onProgress : @escaping (_ progress : Int, _ status : Int, _ outputPath : String?) -> Void) {
         
          result = onProgress
         
@@ -131,35 +131,36 @@ class ConvertUtil : NSObject,CPDFConverterDelegate{
          switch convertType.uppercased() {
             case ConvertType.PPT.rawValue:
             
-            pdfConvert = CPDFConverterPPT(url: fileURL, password: "")
-             outPutPath = outPutPath.appending("/converted\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSince1970, dateFormat:nil)).pptx")
+             pdfConvert = CPDFConverterPPT(url: fileURL, password: "")
+             outPutPath = outPutPath.appending("/converted_\(fileName)_\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSince1970, dateFormat:nil)).pptx")
+            
             case ConvertType.WORD.rawValue:
-            pdfConvert = CPDFConverterWord(url: fileURL, password: "")
              
-             outPutPath = outPutPath.appending("/converted\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSince1970, dateFormat:nil)).docx")
+             pdfConvert = CPDFConverterWord(url: fileURL, password: "")
+             outPutPath = outPutPath.appending("/converted_\(fileName)_\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSinceNow, dateFormat:nil)).docx")
             
             case ConvertType.EXCEL.rawValue:
             pdfConvert = CPDFConverterExcel(url: fileURL, password: "")
-            outPutPath = outPutPath.appending("/converted\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSince1970, dateFormat:nil)).xlsx")
+            outPutPath = outPutPath.appending("/converted_\(fileName)_\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSinceNow, dateFormat:nil)).xlsx")
             case ConvertType.TXT.rawValue:
               pdfConvert = CPDFConverterTxt(url: fileURL, password: "")
-              outPutPath = outPutPath.appending("/converted\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSince1970, dateFormat:nil)).txt")
+              outPutPath = outPutPath.appending("/converted_\(fileName)_\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSinceNow, dateFormat:nil)).txt")
             
             case ConvertType.IMAGE.rawValue:
               pdfConvert = CPDFConverterImg(url: fileURL, password: "")
-             outPutPath = outPutPath.appending("/converted\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSince1970, dateFormat:nil)).zip")
+             outPutPath = outPutPath.appending("/converted_\(fileName)_\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSinceNow, dateFormat:nil)).zip")
             
             case ConvertType.CSV.rawValue:
               pdfConvert = CPDFConverterCsv(url: fileURL, password: "")
-              outPutPath = outPutPath.appending("/converted\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSince1970, dateFormat:nil)).zip")
+              outPutPath = outPutPath.appending("/converted_\(fileName)_\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSinceNow, dateFormat:nil)).zip")
             
             case ConvertType.RTF.rawValue:
             pdfConvert = CPDFConverterRtf(url: fileURL, password: "")
-               outPutPath = outPutPath.appending("/converted\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSince1970, dateFormat:nil)).rtf")
+               outPutPath = outPutPath.appending("/converted_\(fileName)_\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSinceNow, dateFormat:nil)).rtf")
             
             case ConvertType.HTML.rawValue:
             pdfConvert = CPDFConverterHtml(url: fileURL, password: "")
-            outPutPath = outPutPath.appending("/converted\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSince1970, dateFormat:nil)).zip")
+            outPutPath = outPutPath.appending("/converted_\(fileName)_\(self.timeIntervalChangetoTimeStr(timeInterval: NSDate().timeIntervalSinceNow, dateFormat:nil)).zip")
                
             default:
             pdfConvert = CPDFConverter()

+ 5 - 5
ios/Runner/Info.plist

@@ -33,11 +33,11 @@
 	<key>UIMainStoryboardFile</key>
 	<string>Main</string>
 	<key>UISupportedInterfaceOrientations</key>
-	<array>
-		<string>UIInterfaceOrientationPortrait</string>
-		<string>UIInterfaceOrientationLandscapeLeft</string>
-		<string>UIInterfaceOrientationLandscapeRight</string>
-	</array>
+	<array/>
+	<key>UIFileSharingEnabled</key>
+	<true/>
+	<key>LSSupportsOpeningDocumentsInPlace</key>
+	<true/>
 	<key>UISupportedInterfaceOrientations~ipad</key>
 	<array>
 		<string>UIInterfaceOrientationPortrait</string>

+ 1 - 1
lib/states/convert_provider.dart

@@ -34,7 +34,7 @@ class ConvertProvider extends ChangeNotifier {
             tag:
                 '${path}_${convertType}_${DateTime.now().millisecondsSinceEpoch}',
             filePath: path,
-            fileName: basename(path),
+            fileName: basenameWithoutExtension(path),
             convertType: convertType.name,
             status: convertConverting,
             progress: 0,

+ 6 - 5
lib/widgets/convert_list_widget.dart

@@ -1,8 +1,8 @@
+
 import 'package:ConversionFlutterDemo/models/convert_bean.dart';
 import 'package:ConversionFlutterDemo/states/convert_provider.dart';
 import 'package:flutter/material.dart';
-import 'package:open_filex/open_filex.dart';
-// import 'package:open_file/open_file.dart';
+import 'package:open_file/open_file.dart';
 import 'package:provider/provider.dart';
 
 ///  convert_list_widget.dart
@@ -48,16 +48,17 @@ class _ConvertListWidgetState extends State<ConvertListWidget> {
                   style: const TextStyle(fontSize: 18),
                 ),
                 subtitle: Text(
-                  "PDF${bean.convertType.toUpperCase()} ${bean.outputPath != null ? "\n${bean.outputPath}" : ''}",
+                  "PDF convert ${bean.convertType.toUpperCase()} ${bean.outputPath != null ? "\n${bean.outputPath}" : ''}",
                   style: const TextStyle(fontSize: 12),
                 ),
                 trailing: Text(bean.getStatusName()),
                 // item 直观感受是整体大小
                 contentPadding:
                     const EdgeInsets.symmetric(horizontal: 12, vertical: 2),
-                onTap: () {
+                onTap: () async {
+                  print('ontap list status:${status}, path:${bean.outputPath}');
                   if (status == convertSuccess) {
-                    OpenFilex.open(bean.outputPath);
+                    OpenFile.open(bean.outputPath);
                   }
                 },
               ),

+ 9 - 9
pubspec.lock

@@ -58,7 +58,7 @@ packages:
     source: hosted
     version: "1.3.1"
   ffi:
-    dependency: transitive
+    dependency: "direct overridden"
     description:
       name: ffi
       sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
@@ -69,10 +69,10 @@ packages:
     dependency: "direct main"
     description:
       name: file_picker
-      sha256: d090ae03df98b0247b82e5928f44d1b959867049d18d73635e2e0bc3f49542b9
+      sha256: d8e9ca7e5d1983365c277f12c21b4362df6cf659c99af146ad4d04eb33033013
       url: "https://pub.dev"
     source: hosted
-    version: "5.2.5"
+    version: "5.2.6"
   flutter:
     dependency: "direct main"
     description: flutter
@@ -90,10 +90,10 @@ packages:
     dependency: transitive
     description:
       name: flutter_plugin_android_lifecycle
-      sha256: "4bef634684b2c7f3468c77c766c831229af829a0cd2d4ee6c1b99558bd14e5d2"
+      sha256: c224ac897bed083dabf11f238dd11a239809b446740be0c2044608c50029ffdf
       url: "https://pub.dev"
     source: hosted
-    version: "2.0.8"
+    version: "2.0.9"
   flutter_test:
     dependency: "direct dev"
     description: flutter
@@ -152,14 +152,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "1.0.0"
-  open_filex:
+  open_file:
     dependency: "direct main"
     description:
-      name: open_filex
-      sha256: "854aefd72dfd74219dc8c8d1767c34ec1eae64b8399a5be317bddb1ec2108915"
+      name: open_file
+      sha256: "5cd0288033d613ee7908aa974b7ff00805ae55d253f64d311603cf2e30613ca8"
       url: "https://pub.dev"
     source: hosted
-    version: "4.3.2"
+    version: "3.2.1"
   path:
     dependency: transitive
     description:

+ 4 - 2
pubspec.yaml

@@ -14,9 +14,8 @@ dependencies:
   cupertino_icons: ^1.0.2
   file_picker: ^5.2.5
   provider: ^6.0.5
-#  open_file: ^3.2.1
+  open_file: ^3.2.1
   permission_handler: ^10.2.0
-  open_filex: ^4.3.2
 
 dev_dependencies:
   flutter_test:
@@ -25,6 +24,9 @@ dev_dependencies:
 
   flutter_lints: ^2.0.0
 
+dependency_overrides:
+  ffi: ^2.0.1
+
 flutter:
   uses-material-design: true
 

+ 0 - 30
test/widget_test.dart

@@ -1,30 +0,0 @@
-// This is a basic Flutter widget test.
-//
-// To perform an interaction with a widget in your test, use the WidgetTester
-// utility in the flutter_test package. For example, you can send tap and scroll
-// gestures. You can also use WidgetTester to find child widgets in the widget
-// tree, read text, and verify that the values of widget properties are correct.
-
-import 'package:flutter/material.dart';
-import 'package:flutter_test/flutter_test.dart';
-
-import 'package:kmpdfkit_demo/main.dart';
-
-void main() {
-  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
-    // Build our app and trigger a frame.
-    await tester.pumpWidget(const MyApp());
-
-    // Verify that our counter starts at 0.
-    expect(find.text('0'), findsOneWidget);
-    expect(find.text('1'), findsNothing);
-
-    // Tap the '+' icon and trigger a frame.
-    await tester.tap(find.byIcon(Icons.add));
-    await tester.pump();
-
-    // Verify that our counter has incremented.
-    expect(find.text('0'), findsNothing);
-    expect(find.text('1'), findsOneWidget);
-  });
-}