Flutter Save Images as String in SQLite Database

Flutter Knowledge Sharing #59

Geno Tech
3 min readJul 22, 2022

Welcome to my next Flutter article about image saving in SQLite DB as a String. There have many ways to pick an image from the gallery and save it in your application for further use. Here I show you how we can encode an image as a String and decode it. Also, I want to say that this is a common use case in mobile applications. Let’s see how we can do it using the Flutter app development framework. Here I plan to show you how to pick an image from the gallery and save it in the SQLite Database as a string after encoding it, and finally, how to decode it and show it in a list view. Here the most useful parts are how to encode the image to a String and How to decode it into an image. Here we go !!!

Adding Dependencies

First, you must add the following dependencies to your pubspec.yaml.

sqflite: ^2.0.3
path_provider: ^2.0.11
async:io: ^1.0.3
shared_preferences: ^2.0.15
image_picker: ^0.8.5+3

Creating the Model

Create the model class called photo, which is used to upload and retrieve an image.

class photo {
late int? id = 0;
late String? photoName = "";
photo(int i, String imgString){
this.photoName = imgString;
}…

--

--

Geno Tech
Geno Tech

Written by Geno Tech

Software Development | Data Science | AI — We write rich & meaningful content on development, technology, digital transformation & life lessons.

Responses (1)