简体   繁体   中英

Which File_Picker plugin for flutter is currently working?

i'm new to flutter, it seems all updated version of file_picker not working with their initial codes like

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() : '...';
      });
    }
  }

i get error with .CUSTOM and getMultiFilePath i have tried all possible import for the codes, and those files got underlined in red, not solutions

and i'm getting this error

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 should work.

dependencies:
  file_picker: ^3.0.0

In the file:

import 'package:file_picker/file_picker.dart';

Single files:

FilePickerResult result = await FilePicker.platform.pickFiles();

if(result != null) {
   File file = File(result.files.single.path);
} else {
   // User canceled the picker
}

Multiple files:

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM