json_store 1.0.2

json_store #

A Storage solution somewhat similar to a browser's localStorage in the sence that it is a key value pair storage. The value should be a dart reprisentation of a JSON Object (aka a Map<String, dynamic>)

Features #

  • Data is stored in sqflite Database
  • Data may be fully encrypted (encrypt)
  • Encryption keys are stored in Keychain and Keystore thanks to flutter_secure_storage
  • Because the DB schema never changes, there is no concern about database migrations
  • Batch processing
  • Data stored has a time to live. Whenever a getItem is done on a key which ttl has expired, that key will be deleted and a null value will be returned

Getting Started #

In your flutter project add the dependency:


For help getting started with Flutter, view the online documentation.

Usage example #

See example folder for full sample app

Note: JsonStore is a singleton and instantiating with factory constructor JsonStore() will only ever have one instance

Simple example #

import 'package:json_store/json_store.dart';

class CounterModel {
  int value;
  CounterModel.fromJson(Map<String, dynamic> json) : this.value = json['value'];
  Map<String, dynamic> toJson() => {'value': value};


JsonStore jsonStore = JsonStore();
CounterModel counter;

loadFromStorage() async {
  Map<String, dynamic> json = await jsonStore.getItem('counter');
  counter = json != null ? CounterModel.fromJson(json) : CounterModel(0);

incrementCounter() async {
  await jsonStore.setItem('counter', counter.toJson());


Batch example #

When adding a lot of data at a time (Like a long list of messages), use the batch feature as it will improve performance significantly

class Message {
  final int id;
  final String title;
  final String body;
  Message([this.id, this.title, this.body]);
  Message.fromJson(Map<String, dynamic> json)
      : this.id = json['id'],
        this.title = json['title'],
        this.body = json['body'];
  Map<String, dynamic> toJson() => {
        'id': id,
        'title': title,
        'body': body,

saveBigList() {
  Batch batch = await jsonStore.startBatch();
  await Future.forEach(_messages, (message) async {
    await jsonStore.setItem(
      batch: batch,

loadBigList() {
      List<Map<String, dynamic>> json = await jsonStore.getListLike('messages-%');

    messages = json != null
        ? json.map((messageJson) => Message.fromJson(messageJson)).toList()
        : [];


Configure Android #

In [project]/android/app/build.gradle set minSdkVersion to >= 18.

android {
    defaultConfig {
        minSdkVersion 18

Thanks #

Thanks to contributors

[1.0.2] - 2019-11-11

  • Update dependencies

[1.0.1+1] - 2019-09-21

  • Fix readme

[1.0.1] - 2019-09-21

  • Add ability to provide optional database name
  • Updated readme, explaining singleton

[1.0.0] - 2019-09-21

  • Initial Release


examples #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  json_store: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:json_store/json_store.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 21, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health suggestions

Format lib/src/json_store.dart.

Run flutter format to format lib/src/json_store.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (encrypt).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
encrypt ^3.3.1 3.3.1 4.0.0
flutter 0.0.0
flutter_secure_storage ^3.3.1+1 3.3.1+1
path_provider ^1.4.0 1.6.1
sqflite ^1.1.7+2 1.2.1
Transitive dependencies
args 1.5.2
asn1lib 0.5.15 0.6.4
charcode 1.1.3
clock 1.0.1
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
meta 1.1.8
path 1.6.4
platform 2.2.1
pointycastle 1.0.2
sky_engine 0.0.99
synchronized 2.2.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies