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

패키지 상세v2.0.4

json_store

브라우저의 localStorage와 비슷하지만 훨씬 강력한 플러터 저장 솔루션

AndroidiOSmacOS
30일 다운로드
2.6천
좋아요
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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.