基本上,我有一个外部数据库,其中有存储为BLOB的图像。我设法检索了数据,但是我不知道一旦检索到它是什么字节?一个字符串?
此外,我从另一个类初始化了一个“ var frontImage”
我尝试将其转换为BoxDecoration的MemoryImage内的_bytesImage,但显示为
程序包:flutter / src / painting / image_provider.dart:断言失败 行x pos x字节!=空:不正确。
class Vocabulary {
int _id;
String _word;
int _category;
var _frontimage; <-----
//Assume i have getters and setters
}
Uint8List _bytesImage;
int photoIndex = 0;
//My main screen class [not main.dart]
@override
void initState(){
super.initState();
final Future<Database> dbFuture = widget._databaseHelper.initDatabase();
dbFuture.then((database){
Future<List <Vocabulary>> listFuture = widget._databaseHelper.getVocabularyByCategory(1);
listFuture.then((list){
setState(() {
widget.photos = list;
});
});
});
}
void _nextImage() { // next
setState(() {
photoIndex++;
print("ID: " + widget.photos[photoIndex].id.toString() + "\n"
"VOCABULARYWORD: " + widget.photos[photoIndex].word.toString() + "\n"
"CATEGORY: " + widget.photos[photoIndex].category.toString() + "\n"
"++++++++++++++++++++\n");
print(widget.photos[photoIndex].frontimage.toString());
var blob = widget.photos[photoIndex].frontimage;
_bytesImage = Base64Decoder().convert(blob);
}
);}
//My Widget build
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
image: DecorationImage(
image: MemoryImage(_bytesImage), //images front
fit: BoxFit.cover)),
),
I wanted to convert whatever my var frontImage is, into a picture in my widget build.
我想将自己的var frontImage转换为小部件版本中的图片。