[英]Which File_Picker plugin for flutter is currently working?
我是 flutter 的新手,似乎所有更新版本的 file_picker 都無法使用它們的初始代碼,例如
String _fileName;
String _path;
Map<String, String> _paths;
String _extension;
bool _multiPick = false;
bool _hasValidMime = false;
FileType _pickingType;
TextEditingController _controller = new TextEditingController();
@override
void initState() {
super.initState();
_controller.addListener(() => _extension = _controller.text);
}
void _openFileExplorer() async {
if (_pickingType != FileType.CUSTOM || _hasValidMime) {
try {
if (_multiPick) {
_path = null;
_paths = await FilePicker.getMultiFilePath(
type: _pickingType, fileExtension: _extension);
} else {
_paths = null;
_path = await FilePicker.getFilePath(
type: _pickingType, fileExtension: _extension);
}
} on PlatformException catch (e) {
print("Unsupported operation" + e.toString());
}
if (!mounted) return;
setState(() {
_fileName = _path != null
? _path.split('/').last
: _paths != null ? _paths.keys.toString() : '...';
});
}
}
我在使用.CUSTOM
和getMultiFilePath
時遇到錯誤我已經嘗試了所有可能的代碼導入,這些文件用紅色下划線,而不是解決方案
我收到了這個錯誤
I/flutter (20192): [MethodChannelFilePicker] Unsupported operation. Method not found. The exception thrown was: MissingPluginException(No implementation found for method any on channel miguelruivo.flutter.plugins.filepicker)
E/flutter (20192): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method any on channel miguelruivo.flutter.plugins.filepicker)
E/flutter (20192): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
E/flutter (20192): <asynchronous suspension>
E/flutter (20192): #1 MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:344:35)
E/flutter (20192): <asynchronous suspension>
E/flutter (20192): #2 FilePickerIO._getPath (package:file_picker/src/file_picker_io.dart:88:33)
E/flutter (20192): <asynchronous suspension>
E/flutter (20192): #3 _NewreportState._initstat (package:gtbankapp/newreport.dart:31:9)
E/flutter (20192): <asynchronous suspension>```
file_picker應該可以工作。
dependencies:
file_picker: ^3.0.0
在文件中:
import 'package:file_picker/file_picker.dart';
單個文件:
FilePickerResult result = await FilePicker.platform.pickFiles();
if(result != null) {
File file = File(result.files.single.path);
} else {
// User canceled the picker
}
多個文件:
FilePickerResult result = await FilePicker.platform.pickFiles(allowMultiple: true);
if(result != null) {
List<File> files = result.paths.map((path) => File(path)).toList();
} else {
// User canceled the picker
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.