[英]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.