パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.0.4

json_store

ブラウザの localStorage に似たFlutterストレージソリューション(ただし、非常にパワフル)

AndroidiOSmacOS
30日間ダウンロード
2590
いいね数
39
Pub ポイント
150

パッケージをインストール

flutter pub add json_store

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

json_store は、ブラウザの localStorage を参考にした永続的で、NoSQL風のストレージソリューションを提供するFlutterパッケージです。Android、iOS、macOS上でアプリ再起動後もJSONシリアライズ可能なデータの保存と取得が簡単に行えます。シンプルさとパフォーマンスを意識して設計されており、非同期操作および自動的なシリアル化/デシリアライズをサポートしており、フルデータベースのセットアップなしにユーザー設定やキャッシュデータ、小規模なデータセットを保存するのに最適です。

用途

  • ユーザーの設定を保存する
  • API レスポンスのキャッシュ
  • アプリケーション状態の永続化
  • フォームデータの保存
  • ローカル構成の管理
  • オフラインデータの処理

主な機能

  • JSONベースのストレージ
  • クロスプラットフォーム対応
  • 非同期操作
  • 自動シリアル化
  • シンプルな API
  • 軽量で高速

適している対象

  • 小規模から中規模のデータストレージ
  • オフライン機能を必要とするアプリ
  • プロトタイピングまたはMVP開発
  • シンプルなデータ永続化の必要性
  • 複雑なデータベースを避ける開発者

注意事項

  • 大規模なデータセットには適していません
  • 制限されたクエリ機能
  • 組み込みのデータ同期なし
  • シンプルなキー値パターンに最適
  • 複雑な関係をサポートしていません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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:

dependencies:
  ...
  json_store:
  ...

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(this.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 {
  counter.value++;
  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(
      'messages-${message.id}',
      message.toJson(),
      batch: batch,
    );
  });
  jsonStore.commitBatch(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

カテゴリー

依存関係

依存関係一覧 4 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。