【发布时间】:2021-08-20 07:05:07
【问题描述】:
我使用了 file_picker 库,因此用户可以选择他最喜欢的图像,然后将其用作我的应用程序中的背景图像。问题是,我无法正确投射。这是一些代码:
floatingActionButton: FloatingActionButton(
onPressed: () async {
final result = await FilePicker.platform.pickFiles(type: FileType.any, allowMultiple: false);
if (result != null) {
var fileBytes = result.files.first.bytes;
if (fileBytes != null) {
blogimage = Image.memory(fileBytes);
setState(() {});
}
}
},
tooltip: 'Select Image',
child: Icon(Icons.select_all),
),
在上面的代码中,我得到了图像。
我正在尝试使用blogimage 作为我的背景图片。
我已经尝试过使用容器但失败了。这是我使用的代码:
Widget build(BuildContext context) {
return Container(
decoration: (blogimage != null)? BoxDecoration(image: DecorationImage(image: blogimage)): null,
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
title: Text(widget.title),
),
.....
得到错误:需要一个“ImageProvider”类型的值,但得到一个“Image”类型的值。
有什么想法吗? 感谢阅读。
【问题讨论】:
标签: flutter dart statefulwidget