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

패키지 상세v2.2.0

simple_json_persistence

간단한 JSON 파일을 기반으로 하는 Flutter 데이터 저장소로, 여러 저장 인스턴스, 스트림 등을 지원합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
296
좋아요
5
Pub 점수
150

패키지 설치

flutter pub add simple_json_persistence

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

간단한 JSON 기반 데이터 지속성을 위한 Flutter 패키지로, 여러 플랫폼에서 구조화된 데이터를 JSON 파일에 저장할 수 있습니다. 여러 개의 독립적인 스토리지 인스턴스, 실시간 데이터 스트림, Dart의 비동기 모델과의 원활한 통합을 지원합니다. 복잡한 데이터베이스 오버헤드 없이 가벼운 파일 기반 저장이 필요한 앱에 적합합니다. 최소한의 설정과 읽기, 쓰기, 변경 사항 감시를 위한 명확한 API를 제공하여 사용이 간편합니다. 완전한 데이터베이스 솔루션이 필요 없는 소규모부터 중규모 앱에 특히 유용합니다.

사용 사례

  • 사용자 선호 사항 저장
  • 세션 간에 앱 상태 저장
  • 로컬 구성 파일 관리
  • 작은 데이터셋 유지
  • 오프라인 데이터 액세스 활성화

주요 기능

  • 여러 스토리지 인스턴스
  • 실시간 데이터 스트리밍
  • 크로스 플랫폼 지원
  • 간단한 API
  • 파일 기반의 JSON 저장

적합한 대상

  • 경량 데이터 저장 필요성
  • 프로토타이핑 및 소규모 앱
  • 오프라인 우선 애플리케이션
  • 복잡한 데이터베이스를 피하는 앱

고려 사항

  • 대규모 데이터 세트에 적합하지 않습니다
  • 제한된 쿼리 기능
  • 내장형 암호화 없음
  • 매우 큰 파일에서는 성능이 저하될 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

simple_json_persistence

codecov Pub Cirrus CI - Base Branch Build Status

Flutter data storage based on simple json files. The main advantage to using for example the shared preference plugin is that:

  1. It is completely written in dart, so no communication with native ios/android code.
  2. It is possible to have multiple storages for different base types. While the shared preferences load the whole data into memory at once, this allows you to split it up into multiple json storage. (e.g. one small storage for app data/config which needs to be loaded on startup and a larger json storage with larger application data).

It is still not suitable for large datasets, since all data will be kept in memory and written into the json file at once, but it's a good middle ground between shared preferences and complicated database.

Getting Started

To make use of SimpleJsonPersistence you have to create your data models to serialize to and from json. I personally prefer to use built_value with it's serialization, or json_serializable.

Anyway, it is recommended that persistence models are immutable.

import 'package:simple_json_persistence/simple_json_persistence.dart';

@JsonSerializable(nullable: false)
class MyModel {
  MyModel({this.property,});

  factory MyModel.fromJson(Map<String, dynamic> json) =>
      _$MyModelFromJson(json);

  Map<String, dynamic> toJson() => _$MyModelToJson(this);

  final String property;
}

void doSomething() async {
  final store = SimpleJsonPersistence.forType(
    (json) => MyModel.fromJson(json),
    name = 'MyModel',
  );
  await store.save(MyModel(property: 'foo'));
  final foo = await store.load();

  // since every SimpleJsonPersistence for the same type/name is the same instance
  // you can also subscribe to changes.
  store.onValueChanged.listen((newValue) {
    print('got a new value $newValue');
  });
}

Usage in flutter (StreamBuilder)

See also the example application.

Widget build(BuildContext context) {
  final store = SimpleJsonPersistence.forType(
      (json) => AppData.fromJson(json),
      defaultCreator: () => AppData(counter: 0));
  return StreamBuilder<AppData>(
    stream: store.onValueChangedAndLoad,
    initialData: store.cachedValue,
    builder: (context, snapshot) => Text('Counter: ${snapshot.data?.counter ?? 'Loading'}'),
  );
}

카테고리

의존성

의존성 목록 8 개

소스 저장소

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