• Stars
    star
    324
  • Rank 125,124 (Top 3 %)
  • Language
    Dart
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fast, extra light and synchronous key-value storage to Get framework

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

More Repositories

1

getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
Dart
9,842
star
2

get_cli

Official Getx CLI
Dart
564
star
3

get_server

A backend server that makes it possible to program with Flutter syntax and reuse existing code
Dart
466
star
4

VideoCompress

Compress videos, remove audio, manipulate thumbnails, and make your video compatible with all platforms through this lightweight and efficient library.
Swift
209
star
5

readmore

A Flutter plugin than allow expand and collapse text dynamically
Dart
209
star
6

flutter_state_managers

A repository that allows you to analyze size, performance, and metrics of Flutter state management approaches
Dart
70
star
7

getx-community

A collaborative repository of GetX usage examples.
35
star
8

easy

The easiest state manager for Flutter.
Dart
19
star
9

getsocket

Dart
18
star
10

getstream

GetStream is the lightest and most performative way of working with events at Dart.
Dart
18
star
11

bloc_boilerplate

A library that contains a well-defined bloc pattern, showing how easy it is to make API-REST requests and error handling using BLoC.
Dart
16
star
12

flutter_web_responsive

A Beauty and responsive flutter web concept
Dart
16
star
13

dart-server-nano

A light, fast, and friendly server written in Dart.
Dart
15
star
14

get_test

A package to facilitate unit tests with Getx
Dart
12
star
15

jonataslaw

10
star
16

corona_virus

Corona virus application using GET. Cases and deaths by country.
Dart
9
star
17

media_utils

An easy helper class to flutter with many support formats. Suport local and web files.
Dart
7
star
18

server_nano

A fast and lightweight HTTP server implementation in Rust.
Rust
5
star
19

picker

flutter plugin for selecting images from the Android and iOS, taking new pictures with the camera and saves photos/videos on Gallery
Objective-C
5
star
20

GameJAM2024

5
star
21

parse-route

A dart route parser package with support to params, urlParams, and wildcards routes
HTML
4
star
22

ikeyboard

A plugin that brings native iOS keyboard behavior to Flutter.
Dart
4
star
23

poprize-plugin-vite

JavaScript
2
star
24

whatsapp_flutter_web

Whatsapp Web messages clone using Flutter Web and Hasura
Dart
2
star
25

photoeditor

A library that lets you apply filters and effects to photos from your device's gallery or camera (android and iOS).
2
star
26

questioning-dataset

A dataset of questions/answers to fine tune IA models
Python
1
star
27

router_matcher

A rust router parser
Rust
1
star