如何在Flutter中将图像数据保存到sqflite数据库中以保持持久性 [英] How to save image data to sqflite database in flutter for persistence

查看:45
本文介绍了如何在Flutter中将图像数据保存到sqflite数据库中以保持持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建Flutter应用程序,我想使数据保持脱机状态.

I'm building a Flutter app where I would like to keep the data offline.

我正在使用相机或图库图像选择器捕获图像,并且能够将该图像存储到 File image 变量中.

I'm capturing an image using the camera or gallery image picker and able to store that image into a File image variable.

File _avatarImg;

void _getImage(BuildContext context, ImageSource source) {
    ImagePicker.pickImage(
      source: source,
      maxWidth: 400.0,
      maxHeight: 400.0,
    ).then((File image) {
      _avatarImg = image;
    });
  }

这很好用,但是我的问题是,我将如何存储此图像以保持持久性?我应该在图像所在的电话中存储到本地媒体目录的字符串链接吗?如果是这样,我会担心图像是否被用户意外删除.还是将图像本身存储到BLOB中的数据库中?最佳做法是什么?

This works perfectly however my question is, how would I go about storing this image for persistence? Should I store a string link to the local media directory in the phone where the image is located? If so, I would be worried if the image was accidentally deleted by a user. Or do I store the image itself to the database in a BLOB? What is the best practice for this?

推荐答案

您可以将图像转换为BASE64,并将图像作为字符串存储在数据库中.检查此链接

You can convert an image to BASE64 and store image as a string in your database. Check this link and this one

这篇关于如何在Flutter中将图像数据保存到sqflite数据库中以保持持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆