![](/img/trans.png)
[英]How to load data from app start from database using SQFLITE in Flutter?
[英]Flutter - SQFlite store and load image from database
我想在 sqflite 数据库中保存一个图像,稍后,我想将它显示在 SliverAppBar 中作为背景。 直到现在我能够保存图像(不确定它是否正确,但没有抛出错误XD):
Directory directory = await getApplicationDocumentsDirectory();
String path = directory.path;
File newImage = await _image.copy('$path/${recipeName.text}.png'); //_image already taken with image_picker plugin
String base64Encoded = base64Encode(newImage.readAsBytesSync());
这个字符串我保存在数据库中。 但我也想显示。 据我所知,我必须得到字符串,但从现在开始,我不知道如何进一步。 我写了一个函数来获取字符串,但不知道我应该用这个字符串做什么。 该函数如下所示:
Future fetchRecipe(String name) async{
var dbHelper = new DBHelper();
Future<List<Recipes>> recipes = dbHelper.getSpecRecipe(name);
return recipes;
}
getSpecRecipe(name)
指向这个函数:
Future<List<Recipes>> getSpecRecipe(String recipeName) async{
List<Map> list = await _db.rawQuery("SELECT * FROM recipes WHERE name = ?", [recipeName]);
List<Recipes> recipes = new List();
for(int i =0; i < list.length; i++){
recipes.add(new Recipes(list[i]["id"], list[i]["name"], list[i]["definition"], list[i]["duration"], list[i]["favorite"], list[i]["timestamp"], list[i]["image"], list[i]["backgroundColor"]));
}
return recipes;
}
如果有人能够解决我的问题,那就太棒了。 提前致谢XD
从提供的片段来看,您似乎正在尝试将图像保存为数据库中的 base64。 正如@Nordeast 在评论中所提到的,最好将图像保存在设备的存储中并改为存储文件路径。 此外,鉴于提供的片段,很难在本地复制行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.