패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소fstof/flutter_json_store

flutter_json_store

브라우저의 localStorage와 비슷한 Flutter 저장 솔루션

flutter_json_store 프로젝트 이미지
스타
11
포크
9
최근 푸시(UTC)
2026. 7. 7.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

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

Frans Stofberg GitHub avatar
GitHub 작성자

Frans Stofberg ↗

South Africa
언어DartRubySwiftKotlinObjective-C

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 6 개

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗