April 18, 2024, 4:59 p.m. | Irene Duke

DEV Community dev.to

In Flutter, you can use the shared_preferences package to store and retrieve data using shared preferences easily. Shared preferences are a simple way to store key-value pairs persistently across user sessions.



  1. Add the shared_preferences dependency to your pubspec.yaml file:-


dependencies:

flutter:

sdk: flutter

shared_preferences: ^2.0.0



  1. Import the shared_preferences package in your Dart file:-


import 'package:shared_preferences/shared_preferences.dart';


3.Storing Data with Shared Preferences:


Future saveData() async {

SharedPreferences prefs = await SharedPreferences.getInstance();


// Storing data

prefs.setString('username', 'JohnDoe');

prefs.setInt('age', 30);

prefs.setBool('isLogged', true);


print('Data saved …

dart data dependencies design developers file flutter import key package sdk simple store value yaml

Data Architect

@ University of Texas at Austin | Austin, TX

Data ETL Engineer

@ University of Texas at Austin | Austin, TX

Lead GNSS Data Scientist

@ Lurra Systems | Melbourne

Senior Machine Learning Engineer (MLOps)

@ Promaton | Remote, Europe

Sr. VBI Developer II

@ Atos | Texas, US, 75093

Wealth Management - Data Analytics Intern/Co-op Fall 2024

@ Scotiabank | Toronto, ON, CA