flutter_local_prefs 0.0.1
flutter_local_prefs: ^0.0.1 copied to clipboard
A Flutter plugin to manage local preferences using UserDefaults and SharedPreferences.
flutter_local_prefs
#
This Flutter plugin allows you to securely store, retrieve, and manage local preferences, including strings, integers, booleans, and more, across both Android and iOS platforms. All preferences are encrypted to ensure data protection and privacy on the device.
Pre-Requisites #
Android #
Ensure your minSdkVersion is set to 19 or higher in your android/app/build.gradle:
minSdkVersion 19
iOS #
Minimum supported iOS version is 12.0. Ensure this is set in your iOS project configuration.
Get Started #
Installation #
Add the dependency to your pubspec.yaml.
dependencies:
flutter_local_prefs: ^0.0.1
Import #
import 'package:flutter_local_prefs/flutter_local_prefs.dart';
Usage #
Below is a simple example for saving and retrieving a string from local preferences.
FlutterLocalPrefs flutterLocalPrefs = FlutterLocalPrefs();
// Save data
await flutterLocalPrefs.saveData(object: "objects", key: "test");
// Retrieve string data
String key = await flutterLocalPrefs.getString(key: "test");
Available Methods #
class FlutterLocalPrefs {
Future saveData({
required Object object,
required String key,
bool isPersistent = false,
}) async {}
Future<int> getInt({
required String key,
bool isPersistent = false,
}) async {}
Future<String> getString({
required String key,
bool isPersistent = false,
}) async {}
Future<bool> getBool({
required String key,
bool isPersistent = false,
}) async {}
Future<double> getDouble({
required String key,
bool isPersistent = false,
}) async {}
Future getLong({
required String key,
bool isPersistent = false,
}) async {}
Future removeAll({bool isPersistent = false}) async {}
Future remove({
required String key,
bool isPersistent = false,
}) async {}
Future<bool> contain({
required String key,
bool isPersistent = false,
}) async {}
}
Detailed Functions: #
- saveData: Saves an object (String, int, bool, etc.) under a specific key.
- getInt / getString / getBool / getDouble / getLong: Retrieve data of the specified type.
- remove: Deletes the data stored with the specified key.
- removeAll: Deletes all stored data.
- contain: Checks if data with the specified key exists.
For a full API reference, please visit the official documentation.