Google developed the open-source Flutter mobile application creation framework. From a single codebase, it enables developers to create high-performance, natively compiled applications for desktop, web, and mobile platforms.
Dart, another Google-developed programming language, is used by Flutter. It is simple to design stunning, responsive user interfaces with animations and intricate interactions thanks to the framework’s extensive selection of configurable widgets and tools.
One of Flutter’s key benefits is its “hot reload” feature, which enables programmers to rapidly see changes they’ve made to their code in real-time on a device or emulator without having to restart the entire application. The development process can be significantly accelerated as a result, and iterating on designs and features will be simpler.
With the help of the well-liked mobile app creation framework Flutter, you can create native mobile apps for both the Android and iOS platforms that are fast, gorgeous, and responsive. Here are some essential guidelines for Flutter beginners:
Learn the Dart computer language because Flutter relies on it, making a solid command of the language a requirement. Dart is a cutting-edge, simple-to-learn programming language intended for creating online and mobile applications.
Learn about the Flutter Framework. The Flutter framework is a robust collection of tools, widgets, and libraries on top of which Flutter is constructed. Learn how to use the framework’s essential tools and parts as well as how to make your own.
Shared preference
How can we perform crud operation using Shared Preference??
Shared Preferences is a key-value storage system in Flutter that allows you to store and retrieve small amounts of data on the device. It is often used to store user preferences, app settings, and other data that needs to persist across app sessions.
SharedPreferences works by storing data as key-value pairs, where the key is a String and the value can be a String, int, bool, or double. The data is stored in a file on the device’s file system, which can be accessed and modified as needed.
Shared Preferences is a simple and easy-to-use way to store data on the device without having to set up a more complex database or file system. It is particularly useful for storing small amounts of data, such as user preferences or settings, as it provides a quick and efficient way to access and modify this data.
Shared Preferences is a key-value storage system in Flutter that allows you to store and retrieve data on the device. Here are the steps to use Shared Preferences in Flutter:
- Import the SharedPreferences package: Add the following line to your project’s pubspec.yaml file:

Then, run “flutter pub get” in your terminal to install the package.
2.Import the package: Import the Shared Preferences package in your Dart code:

3)Create a Shared Preferences instance: You can create a Shared Preferences instance using the get Instance()
method:

4)Store data in Shared Preferences: You can store data using the setString()
, setInt()
, setBool()
, and other similar methods:

5)etrieve data from SharedPreferences: You can retrieve data using the getString()
, getInt()
, getBool()
, and other similar methods:

If a key does not exist in SharedPreferences, the get
methods will return null
.
Code for shared preference:
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SharedPref extends StatefulWidget {
@override
State<SharedPref> createState() => _SharedPrefState();
}
class _SharedPrefState extends State<SharedPref> {
final _nameController = TextEditingController();
final _emailController = TextEditingController();
final _phoneController = TextEditingController();
final _positionController = TextEditingController();
void initState() {
super.initState();
getValue();
}
// const SharedPref({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 172, 142, 207),
centerTitle: true,
title: Text(
"Shared Preferences",
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black),
),
),
body: SingleChildScrollView(
child: Container(
color: Color.fromARGB(255, 219, 133, 133),
child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _nameController, // obscureText: true,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Enter your Name',
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
// obscureText: true,
controller: _emailController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Enter your Email',
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _phoneController,
obscureText: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Enter your Phone Number',
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _positionController,
obscureText: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Position',
),
),
),
// SizedBox(
// height: 11,
// ),
ElevatedButton(
onPressed: () async {
var prefs = await SharedPreferences.getInstance();
prefs.setString('Name', _nameController.text);
prefs.setString('Email', _emailController.text);
prefs.setString('Phone', _phoneController.text);
prefs.setString('Position', _positionController.text);
setState(() {});
},
// onPressed: (() async {
// // var name = _nameController.text.toString();
// var prefs = await SharedPreferences.getInstance();
// prefs.setString(KEYNAME, _nameController.text.toString());
// }),
child: const Text(
"Save",
style: TextStyle(color: Colors.black),
)),
FutureBuilder(
future: getValue(),
builder: ((context, snapshot) {
if (snapshot.hasData) {
Map data = snapshot.data as Map;
return ListTile(
title: Column(
children: [
Text(data['name'] ?? "Khali bharw ma aako haii"),
Text(data['phone'] ?? "Khali bharw ma aako haii"),
Text(data['email'] ?? "Khali bharw ma aako haii"),
Text(data['position'] ?? "Khali bharw ma aako haii"),
],
),
subtitle:
Text(data['phone'] ?? "Khali bharw ma aako haii"),
);
}
return CircularProgressIndicator();
}),
)
],
),
),
),
);
}
Future<Map<String, dynamic>> getValue() async {
var prefs = await SharedPreferences.getInstance();
// prefs.get(KEYNAME);
var getNAme = prefs.getString('Name');
var getEmail = prefs.getString('Email');
var getPhone = prefs.getString('Phone');
var getPosition = prefs.getString('Position');
return {
'name': getNAme,
'email': getEmail,
'phone': getPhone,
'position': getPosition,
};
}
}
OUTPUT:
