simple_shared_pref

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

simple shared pref

SimpleSharedPref #
SimpleSharedPref is a Flutter package that provides easy access to shared preferences.
It follows the singleton design pattern, allowing you to conveniently store and retrieve
data in shared preferences. It also supports optional encryption and decryption of sensitive data using the CryptoModule class.
Installation #
Add the following dependency to your pubspec.yaml file:
dependencies:
simple_shared_pref: ^2.0.0
copied to clipboard
Usage #
Import the package and the SimpleSharedPref class in your Dart file:
import 'package:simple_shared_pref/simple_shared_pref.dart';
copied to clipboard
Create an instance of SimpleSharedPref:
SimpleSharedPref sharedPref = SimpleSharedPref();
copied to clipboard
Initialize the shared preferences by calling the init method.
It's recommended to do this in the main function or at the start of your application:
void main()

async {
WidgetsFlutterBinding.ensureInitialized();
await sharedPref.init();
runApp(MyApp());
}
copied to clipboard
Storing and Retrieving Values #
You can store and retrieve various types of values in shared preferences:
// Store an integer value
sharedPref.setValue < int > ('counter', 10 );

// Retrieve the integer value
int ? counterValue = sharedPref.getValue < int > ('counter');

// Store a string value
sharedPref.setValue <String> ('username', 'JohnDoe' );

// Retrieve the string value
String ? username = sharedPref.getValue <String> ('username');

// Store a boolean value
sharedPref.setValue <bool> ('isLoggedIn', true );

// Retrieve the boolean value
bool ? isLoggedIn = sharedPref.getValue <bool> ('isLoggedIn');
copied to clipboard
Removing a Value #
To remove a value from shared preferences, you can use the removeValue method:

sharedPref.removeValue('counter');
copied to clipboard
Checking if a Value Exists #
You can check if a value exists in shared preferences using the containsKey method:

bool isUsernameStored = sharedPref.containsKey('username');

copied to clipboard
Clearing Shared Preferences #
To clear all values stored in shared preferences, use the clear method:

sharedPref.clear();

copied to clipboard
Contributing #
Contributions are welcome! If you encounter any issues or have suggestions for improvements,
please create an issue or submit a pull request on
the GitHub repository .
License #
This package is released under the MIT License. See
the LICENSE file for more
details.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.

Related Products

More From This Creator