【发布时间】:2020-01-21 06:21:15
【问题描述】:
我是 Flutter 新手,我正在构建一个应用程序,我需要将使用 image_picker 包后生成的文件(图像)转换为资产图像以在应用程序中使用。
示例代码如下,创建文件(图片)
final Function onSelectImage;
ImageInput(this.onSelectImage);
File _storedImage;
Future<void> _takePicture() async {
final imageFile = await ImagePicker.pickImage(
source: ImageSource.camera,
maxWidth: 600,
);
if (imageFile == null) {
return;
}
setState(() {
_storedImage = imageFile;
});
final appDir = await syspaths.getApplicationDocumentsDirectory();
final fileName = path.basename(imageFile.path);
final savedImage = await imageFile.copy('${appDir.path}/$fileName');
widget.onSelectImage(savedImage);
}
提前致谢
【问题讨论】:
标签: flutter flutter-image