Skip to content

Commit 919a561

Browse files
committed
Integrated flutter_file_picker for improved testing
1 parent 3877f18 commit 919a561

File tree

6 files changed

+79
-8
lines changed

6 files changed

+79
-8
lines changed

open_file_mac/example/lib/main.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22

3+
import 'package:file_picker/file_picker.dart';
34
import 'package:flutter/material.dart';
45
import 'package:open_file_mac/open_file_mac.dart';
56

@@ -13,6 +14,16 @@ class MyApp extends StatefulWidget {
1314
class _MyAppState extends State<MyApp> {
1415
var _openResult = 'Unknown';
1516

17+
Future<void> _openPickFile() async {
18+
FilePickerResult? fileResult = await FilePicker.platform.pickFiles();
19+
if (fileResult?.files.first != null) {
20+
final result = await OpenFileMac().open(fileResult!.files.first.path);
21+
setState(() {
22+
_openResult = "type=${result.type} message=${result.message}";
23+
});
24+
}
25+
}
26+
1627
Future<void> openFile() async {
1728
final result =
1829
await OpenFileMac().open("/Users/chendong/Downloads/R-C.jpeg");
@@ -35,7 +46,7 @@ class _MyAppState extends State<MyApp> {
3546
Text('open result: $_openResult\n'),
3647
TextButton(
3748
child: Text('Tap to open file'),
38-
onPressed: openFile,
49+
onPressed: _openPickFile,
3950
),
4051
],
4152
),

open_file_mac/example/macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import FlutterMacOS
66
import Foundation
77

8+
import file_picker
89
import open_file_mac
910

1011
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
12+
FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin"))
1113
OpenFilePlugin.register(with: registry.registrar(forPlugin: "OpenFilePlugin"))
1214
}

open_file_mac/example/macos/Runner/DebugProfile.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
<true/>
99
<key>com.apple.security.network.server</key>
1010
<true/>
11+
<key>com.apple.security.files.user-selected.read-only</key>
12+
<true/>
1113
</dict>
1214
</plist>

open_file_mac/example/macos/Runner/Release.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
<dict>
55
<key>com.apple.security.app-sandbox</key>
66
<true/>
7+
<key>com.apple.security.files.user-selected.read-only</key>
8+
<true/>
79
</dict>
810
</plist>

open_file_mac/example/pubspec.lock

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ packages:
4141
url: "https://pub.dev"
4242
source: hosted
4343
version: "1.19.1"
44+
cross_file:
45+
dependency: transitive
46+
description:
47+
name: cross_file
48+
sha256: "7caf6a750a0c04effbb52a676dce9a4a592e10ad35c34d6d2d0e4811160d5670"
49+
url: "https://pub.dev"
50+
source: hosted
51+
version: "0.3.4+2"
4452
cupertino_icons:
4553
dependency: "direct main"
4654
description:
@@ -57,6 +65,14 @@ packages:
5765
url: "https://pub.dev"
5866
source: hosted
5967
version: "1.3.2"
68+
ffi:
69+
dependency: transitive
70+
description:
71+
name: ffi
72+
sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418"
73+
url: "https://pub.dev"
74+
source: hosted
75+
version: "2.1.4"
6076
file:
6177
dependency: transitive
6278
description:
@@ -65,6 +81,14 @@ packages:
6581
url: "https://pub.dev"
6682
source: hosted
6783
version: "7.0.1"
84+
file_picker:
85+
dependency: "direct main"
86+
description:
87+
name: file_picker
88+
sha256: "8986dec4581b4bcd4b6df5d75a2ea0bede3db802f500635d05fa8be298f9467f"
89+
url: "https://pub.dev"
90+
source: hosted
91+
version: "10.1.2"
6892
flutter:
6993
dependency: "direct main"
7094
description: flutter
@@ -79,15 +103,28 @@ packages:
79103
dependency: "direct dev"
80104
description:
81105
name: flutter_lints
82-
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
106+
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
83107
url: "https://pub.dev"
84108
source: hosted
85-
version: "4.0.0"
109+
version: "5.0.0"
110+
flutter_plugin_android_lifecycle:
111+
dependency: transitive
112+
description:
113+
name: flutter_plugin_android_lifecycle
114+
sha256: "5a1e6fb2c0561958d7e4c33574674bda7b77caaca7a33b758876956f2902eea3"
115+
url: "https://pub.dev"
116+
source: hosted
117+
version: "2.0.27"
86118
flutter_test:
87119
dependency: "direct dev"
88120
description: flutter
89121
source: sdk
90122
version: "0.0.0"
123+
flutter_web_plugins:
124+
dependency: transitive
125+
description: flutter
126+
source: sdk
127+
version: "0.0.0"
91128
fuchsia_remote_debug_protocol:
92129
dependency: transitive
93130
description: flutter
@@ -126,10 +163,10 @@ packages:
126163
dependency: transitive
127164
description:
128165
name: lints
129-
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
166+
sha256: c35bb79562d980e9a453fc715854e1ed39e24e7d0297a880ef54e17f9874a9d7
130167
url: "https://pub.dev"
131168
source: hosted
132-
version: "4.0.0"
169+
version: "5.1.1"
133170
matcher:
134171
dependency: transitive
135172
description:
@@ -278,6 +315,14 @@ packages:
278315
url: "https://pub.dev"
279316
source: hosted
280317
version: "14.3.1"
318+
web:
319+
dependency: transitive
320+
description:
321+
name: web
322+
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
323+
url: "https://pub.dev"
324+
source: hosted
325+
version: "1.1.1"
281326
webdriver:
282327
dependency: transitive
283328
description:
@@ -286,6 +331,14 @@ packages:
286331
url: "https://pub.dev"
287332
source: hosted
288333
version: "3.0.4"
334+
win32:
335+
dependency: transitive
336+
description:
337+
name: win32
338+
sha256: dc6ecaa00a7c708e5b4d10ee7bec8c270e9276dfcab1783f57e9962d7884305f
339+
url: "https://pub.dev"
340+
source: hosted
341+
version: "5.12.0"
289342
sdks:
290-
dart: ">=3.7.0-0 <4.0.0"
291-
flutter: ">=3.18.0-18.0.pre.54"
343+
dart: ">=3.7.0 <4.0.0"
344+
flutter: ">=3.27.0"

open_file_mac/example/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies:
2323
# The following adds the Cupertino Icons font to your application.
2424
# Use with the CupertinoIcons class for iOS style icons.
2525
cupertino_icons: ^1.0.8
26+
file_picker: ^10.1.2
2627

2728
dev_dependencies:
2829
integration_test:
@@ -35,7 +36,7 @@ dev_dependencies:
3536
# activated in the `analysis_options.yaml` file located at the root of your
3637
# package. See that file for information about deactivating specific lint
3738
# rules and activating additional ones.
38-
flutter_lints: ^4.0.0
39+
flutter_lints: ^5.0.0
3940

4041
# For information on the generic Dart part of this file, see the
4142
# following page: https://dart.dev/tools/pub/pubspec

0 commit comments

Comments
 (0)