如何挑选文件和图像以通过Flutter Web上传

我想知道如何将用户计算机中的图像选入我的Flutter Web应用程序中进行上传

回答:

我尝试下面的代码,它的工作。

第一 import 'dart:html';

// variable to hold image to be displayed

Uint8List uploadedImage;

//method to load image and update `uploadedImage`

_startFilePicker() async {

InputElement uploadInput = FileUploadInputElement();

uploadInput.click();

uploadInput.onChange.listen((e) {

// read file content as dataURL

final files = uploadInput.files;

if (files.length == 1) {

final file = files[0];

FileReader reader = FileReader();

reader.onLoadEnd.listen((e) {

setState(() {

uploadedImage = reader.result;

});

});

reader.onError.listen((fileEvent) {

setState(() {

option1Text = "Some Error occured while reading the file";

});

});

reader.readAsArrayBuffer(file);

}

});

}

现在只是任何小部件,例如按钮,然后调用方法 _startFilePicker()

以上是 如何挑选文件和图像以通过Flutter Web上传 的全部内容, 来源链接: utcz.com/qa/429684.html

回到顶部