Flutter-SQFlite从数据库存储和加载图像

时间:2018-10-02 15:08:51

标签: android ios dart flutter

我想将图像保存在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());

这个字符串我要保存在数据库中。但我也想展示。就我所知,我必须获取String,但是从现在开始,我不知道如何进一步。我已经编写了一个获取String的函数,但不知道该如何处理String。该函数如下所示:

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

0 个答案:

没有答案