Remember this
Use device storage for small data your app should remember after it closes. Good examples are favourites, dark mode, last selected city, or whether onboarding is done.
For bigger data, like many notes, orders, or chat messages, key-value storage is not enough. Use a database later.
What to store
In your demo app, pick one thing the user can change and expect to see again. A college events app can save bookmarked events. A UPI expense tracker can save the selected month. A jobs app can save saved internships.
This lesson uses shared_preferences, a common Flutter plugin for simple key-value data. Flutter’s own guide shows it for settings like dark mode.
Add persistence
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done
Save a favourite
This example stores one saved item id. Use it inside a StatefulWidget screen. Replace item42 with your API item id.
The important part is the flow: load once, show current value, save when the user taps.
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class FavouriteButton extends StatefulWidget {
const FavouriteButton({super.key});
@override
State<FavouriteButton> createState() => _FavouriteButtonState();
}
class _FavouriteButtonState extends State<FavouriteButton> {
static const String savedKey = 'saved_item_id';
static const String itemId = 'item42';
bool isSaved = false;
@override
void initState() {
super.initState();
loadSavedState();
}
Future<void> loadSavedState() async {
final prefs = await SharedPreferences.getInstance();
final savedId = prefs.getString(savedKey);
setState(() {
isSaved = savedId == itemId;
});
}
Future<void> toggleSaved() async {
final prefs = await SharedPreferences.getInstance();
if (isSaved) {
await prefs.remove(savedKey);
} else {
await prefs.setString(savedKey, itemId);
}
setState(() {
isSaved = !isSaved;
});
}
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: toggleSaved,
child: Text(isSaved ? 'Saved' : 'Save'),
);
}
}Avoid this
Do not read from storage directly inside build. build can run many times, so your app may repeat work and feel slow.
Also do not store secrets like private API keys in simple local storage. Treat it as app convenience storage, not a secure vault.
Make it testable
Add one clear user action for storage. For example: tap Save, close the app, open it again, and the item is still saved.
Record this in your README later. Recruiters should know exactly how to prove your app stores data on the device.
Do this now
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done