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

패키지 상세v2.1.1

get_storage

전적으로 Dart로 작성된 빠르고 초경량이며 동기식 키-값 저장소

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
21.2만
좋아요
1.9천
Pub 점수
130

패키지 설치

flutter pub add get_storage

패키지 개요

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

GetStorage는 Dart로 완전히 구현된 가벼우면서도 동기식 키-값 저장 솔루션으로, 다양한 플랫폼에서 빠르고 효율적인 데이터 지속성을 위해 설계되었습니다. 비동기 작업 없이 문자열, 숫자, 불리언, 리스트와 같은 기본 데이터 유형을 저장하고 검색할 수 있는 간단한 API를 제공합니다. 소규모 앱 상태 관리나 캐싱에 적합하며, Android, iOS, Web, macOS, Windows, Linux에서 원활하게 작동합니다. 최소한의 크기와 사용의 용이성 덕분에 복잡한 데이터베이스보다 간단한 대안을 찾는 개발자에게 적합합니다.

사용 사례

  • 사용자 선호 사항 저장
  • 작은 데이터 세트 캐싱
  • 앱 설정 유지
  • 세션 데이터 관리
  • 간단한 로컬 상태 관리

주요 기능

  • 동기 작업
  • 가볍고 빠름
  • 다수의 플랫폼을 지원합니다
  • 사용하기 쉬운 API
  • 외부 종속성 없음

적합한 대상

  • 작은에서 중간 규모의 앱
  • 빠른 프로토타이핑
  • 간단한 데이터 지속성 요구 사항
  • 크로스 플랫폼 개발
  • 복잡한 데이터베이스 설정을 피하는 앱

고려 사항

  • 대규모 데이터 세트에 적합하지 않습니다
  • 제한된 쿼리 기능
  • 내장형 암호화 없음
  • 일반 텍스트로 저장된 데이터
  • 간단한 키-값 쌍에만 최적

원본 README

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

get_storage

A fast, extra light and synchronous key-value in memory, which backs up data to disk at each operation. It is written entirely in Dart and easily integrates with Get framework of Flutter.

Supports Android, iOS, Web, Mac, Linux, and fuchsia and Windows**. Can store String, int, double, Map and List

Add to your pubspec:
dependencies:
  get_storage:
Install it

You can install packages from the command line:

with Flutter:

$  flutter packages get
Import it

Now in your Dart code, you can use:

import 'package:get_storage/get_storage.dart';
Initialize storage driver with await:
main() async {
  await GetStorage.init();
  runApp(App());
}
use GetStorage through an instance or use directly GetStorage().read('key')
final box = GetStorage();
To write information you must use write :
box.write('quote', 'GetX is the best');
To read values you use read:
print(box.read('quote'));
// out: GetX is the best

To remove a key, you can use remove:
box.remove('quote');
To listen changes you can use listen:
Function? disposeListen;
disposeListen = box.listen((){
  print('box changed');
});
If you subscribe to events, be sure to dispose them when using:
disposeListen?.call();
To listen changes on key you can use listenKey:
box.listenKey('key', (value){
  print('new key is $value');
});
To erase your container:
box.erase();
If you want to create different containers, simply give it a name. You can listen to specific containers, and also delete them.
GetStorage g = GetStorage('MyStorage');
To initialize specific container:
await GetStorage.init('MyStorage');

SharedPreferences Implementation

class MyPref {
  static final _otherBox = () => GetStorage('MyPref');

  final username = ''.val('username');
  final age = 0.val('age');
  final price = 1000.val('price', getBox: _otherBox);

  // or
  final username2 = ReadWriteValue('username', '');
  final age2 = ReadWriteValue('age', 0);
  final price2 = ReadWriteValue('price', '', _otherBox);
}

...

void updateAge() {
  final age = 0.val('age');
  // or 
  final age = ReadWriteValue('age', 0, () => box);
  // or 
  final age = Get.find<MyPref>().age;

  age.val = 1; // will save to box
  final realAge = age.val; // will read from box
}

Benchmark Result:

GetStorage is not fast, it is absurdly fast for being memory-based. All of his operations are instantaneous. A backup of each operation is placed in a Container on the disk. Each container has its own file.

What GetStorage is:

Persistent key/value storage for Android, iOS, Web, Linux, Mac and Fuchsia and Windows, that combines fast memory access with persistent storage.

What GetStorage is NOT:

A database. Get is super compact to offer you a solution ultra-light, high-speed read/write storage to work synchronously. If you want to store data persistently on disk with immediate memory access, use it, if you want a database, with indexing and specific disk storage tools, there are incredible solutions that are already available, like Hive and Sqflite/Moor.

As soon as you declare "write" the file is immediately written in memory and can now be accessed immediately with box.read(). You can also wait for the callback that it was written to disk using await box.write().

When to use GetStorage:

  • simple Maps storage.
  • cache of http requests
  • storage of simple user information.
  • simple and persistent state storage
  • any situation you currently use sharedPreferences.

When not to use GetStorage:

  • you need indexes.
  • when you need to always check if the file was written to the storage disk before starting another operation (storage in memory is done instantly and can be read instantly with box.read(), and the backup to disk is done in the background. To make sure the backup is complete, you can use await, but if you need to call await all the time, it makes no sense you are using memory storage).
You can use this lib even as a modest persistent state manager using Getx SimpleBuilder

카테고리

의존성

의존성 목록 2 개

소스 저장소

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