get_hooked_storage 0.1.1 copy "get_hooked_storage: ^0.1.1" to clipboard
get_hooked_storage: ^0.1.1 copied to clipboard

Persistent GetValue objects backed by SharedPreferences for get_hooked.

get_hooked_storage #

Persistent GetValue objects backed by SharedPreferences.

Values created with Stored<T> can be used directly with ref.watch(), Get.it, RefPaint, and the rest of the get_hooked ecosystem while being automatically saved to and restored from local storage.

Usage #

import 'package:flutter/material.dart';
import 'package:get_hooked/get_hooked.dart';
import 'package:get_hooked_storage/get_hooked_storage.dart';

// In main(), before runApp:
await Stored.init();

final counter = Stored('counter', 0);
final themeMode = Stored.enumValue(ThemeMode.values, ThemeMode.system);

class MyApp extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final mode = ref.watch(themeMode);
    final count = ref.watch(counter);
    return MaterialApp(
      themeMode: mode,
      home: Text('count: $count'),
    );
  }
}

// Later:
counter.value = 1; // persists automatically
await themeMode.save(ThemeMode.dark); // or await the write

Supported types #

  • bool, int, double, String, List<String>
  • Color and Color?
  • Nullable versions of the above
  • Enums via Stored.enumValue(values, initial)
  • Custom types via Stored.custom(key, initial, encode: ..., decode: ...)

Initialization #

Stored.init() must complete before any Stored value is read.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Stored.init();
  runApp(const MyApp());
}

See the library docs for Stored.enumValue, Stored.custom, and the save method.

0
likes
150
points
26
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Persistent GetValue objects backed by SharedPreferences for get_hooked.

Homepage
Repository (GitHub)
View/report issues

Topics

#flutter #state-management #persistence #shared-preferences

License

MIT (license)

Dependencies

flutter, get_hooked, shared_preferences

More

Packages that depend on get_hooked_storage