async_preferences 1.0.1 async_preferences: ^1.0.1 copied to clipboard
A Flutter plugin designed for asynchronous management of local preferences, primarily focused on Android and iOS platforms.
Async Preferences #
A flutter plugin to use local preferences asynchronously.
This plugin stands out for some significant differences compared to other preference management plugins:
- Provides
set
methods to save preferences andget
methods to get them. There is no cache, the source of truth is the underlying preferences API. All operations are performed asynchronously usingFutures
. - No prefix is used, the key you specify is the final key that will be used. Using this plugin you can obtain preferences saved by other components (such as other plugins, libraries or any component that accesses the underliying APIs to save/get preferences).
- Allows you to specify the read/write file on Android, so it is possible to save/get preferences from places other than the default space.
- Support for
long
(Android) andInt64
(iOS) type preferences. In Flutter these values are set and returned asint
, but on the native side the specified types are used.
For now this plugin only supports Android and iOS, it is not planned to support more platforms.
How to use it #
First, import the plugin:
import 'package:async_preferences/async_preferences.dart';
Create an instance of AsyncPreferences:
final preferences = AsyncPreferences();
Save a value:
await preferences.setString('your_key', 'your_value');
Get the value:
final value = await preferences.getString('your_key');
;
Please note that if the value doesn't exist, the get
methods will return null
. You can specify a default value as follows:
final value = await preferences.getString('your_key') ?? 'default_value';
;
Remove a value:
await preferences.remove('your_key');
Save and get a value in a custom file (Android only):
await preferences.setString('custom_file_value', 'your_value', file: 'custom_file');
final value = await preferences.getString('custom_file_value', file: 'custom_file');
How to contribute #
Thank you for your interest in contributing! Pull requests that fix bugs or improve the stability of the project are appreciated. If you plan to open a pull request, be sure to direct it to the develop
branch. This helps to review, test, and merge changes in an orderly manner before including them in the main branch.