Flutter未处理异常:MissingPluginException(在通道plugins.flutter.io/im



我试图在Windows 10上使用image_picker。但是当文件选择屏幕被触发时,我得到如下错误:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:292:7)
<asynchronous suspension>
#1      ImagePicker.pickImage (package:image_picker/image_picker.dart:64:25)
<asynchronous suspension>
#2      _BolatAktarAppState.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:bolataktar_resimyukleme/screens/resimyukleme_main.dart:66:52)
<asynchronous suspension>

这个问题可能是由什么引起的?

代码:

FloatingActionButton.large(
child: Icon(Icons.folder, color: Colors.white, size: 45,),
backgroundColor: Color.fromARGB(255, 36, 36, 36),
onPressed: () async {
final File image = await ImagePicker.pickImage(source: ImageSource.gallery);
if (image == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("the image is not selected."),
backgroundColor: Color.fromARGB(255, 36, 36, 36),
),
);
return null;
}
else {
print("else");
uploadImage("bolat", image);
}
},
),
// ....
void uploadImage(String title, File file) async {
var request = http.MultipartRequest("POST", Uri.parse("https://api.imgur.com/3/image"));
request.fields["title"] = title;
request.headers["Authorization"] = "";
var picture = http.MultipartFile.fromBytes('image', (await rootBundle.load('assets/testimage.png')).buffer.asUint8List(),
filename: 'resimyukle.png');
request.files.add(picture);
var response = await request.send();
var responseData = await response.stream.toBytes();
var result = String.fromCharCodes(responseData);
print(result);
}

谢谢你的帮助。

image_picker不支持Windows Android, iOS和web。

最新更新