shared_preference_signals 1.0.1 copy "shared_preference_signals: ^1.0.1" to clipboard
shared_preference_signals: ^1.0.1 copied to clipboard

A Flutter package that provides reactive SharedPreferences integration using signals.

Shared Preference Signals #

A Flutter package that provides reactive SharedPreferences integration using signals.

Features #

  • Reactive SharedPreferences integration using signals
  • Support for various data types:
    • String
    • int
    • double
    • bool
    • Map
    • DateTime
    • ThemeMode
    • List
    • Matrix4
  • JSON serialization support
  • Enum support
  • Error handling and logging
  • Type-safe API

Installation #

Add the package to your pubspec.yaml:

dependencies:
  shared_preference_signals: ^1.0.0

Usage #

JSON Serialization #

final userSignal = jsonSharedPreferenceSignal<User>(
  key: 'user',
  value: null,
  fromJson: User.fromJson,
  toJson: (user) => user.toJson(),
);

// Use the signal
userSignal.value = User(name: 'John');
final currentUser = userSignal.value;

Enum Support #

final themeSignal = enumSharedPreferenceSignal<ThemeMode>(
  key: 'theme',
  value: ThemeMode.system,
  fromString: ThemeMode.values.byName,
);

// Use the signal
themeSignal.value = ThemeMode.dark;
final currentTheme = themeSignal.value;

Direct SharedPreferences Access #

// Save a value
await saveToSharedPreferences('counter', 42);

// Read a value
final counter = await readFromSharedPreferences<int>('counter');

// Delete a value
await deleteFromSharedPreferences('counter');

Error Handling #

The package includes comprehensive error handling:

  • All operations are wrapped in try-catch blocks
  • Failed operations are logged using debugPrint
  • Default values are returned when operations fail
  • Unsupported types throw UnsupportedError

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

0
likes
150
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package that provides reactive SharedPreferences integration using signals.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, shared_preferences, signals

More

Packages that depend on shared_preference_signals