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

パッケージ詳細v2.1.1

get_storage

Dartで完全に書かれた高速で非常に軽量かつ同期的なキー値ストレージ

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
21.2万
いいね数
1880
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 件

ソースリポジトリ

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