What package is commonly used for simple local storage in Flutter?
SharedPreferences works for small amounts of key-value data. For production notes apps with many entries, consider sqflite or hive for better performance and querying.
Build a notes app with local storage
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
This project combines local storage, CRUD operations, search functionality, and a polished editor experience into one app. You will build a notes application similar to Google Keep where users can create, read, edit, and delete notes. Each note has a title, content, timestamps, and an optional category. Notes are stored on the device using SharedPreferences so they persist across app restarts. This gives you hands-on practice with TextEditingController, navigation with data passing, JSON serialization, and filtering lists.
Features to build:
1// Note model2class Note {3final String id;4String title;5String content;6DateTime createdAt;7DateTime updatedAt;8String? category;910Note({11required this.id,12required this.title,13required this.content,14required this.createdAt,15required this.updatedAt,16this.category,17});1819Map<String, dynamic> toJson() => {20'id': id,21'title': title,22'content': content,23'createdAt': createdAt.toIso8601String(),24'updatedAt': updatedAt.toIso8601String(),25'category': category,26};2728factory Note.fromJson(Map<String, dynamic> json) => Note(29id: json['id'],30title: json['title'],31content: json['content'],32createdAt: DateTime.parse(json['createdAt']),33updatedAt: DateTime.parse(json['updatedAt']),34category: json['category'],35);36}
1// Notes storage service2class NotesStorage {3static const _key = 'notes';45Future<List<Note>> loadNotes() async {6final prefs = await SharedPreferences.getInstance();7final jsonString = prefs.getString(_key);8if (jsonString == null) return [];910final List jsonList = jsonDecode(jsonString);11return jsonList.map((json) => Note.fromJson(json)).toList();12}1314Future<void> saveNotes(List<Note> notes) async {15final prefs = await SharedPreferences.getInstance();16final jsonString = jsonEncode(notes.map((n) => n.toJson()).toList());17await prefs.setString(_key, jsonString);18}19}
The editor screen handles both creating new notes and editing existing ones. It receives an optional existingNote parameter through its constructor. If a note is passed in, the text fields are pre-filled with the existing content. If not, the fields start empty for a new note. Two TextEditingControllers manage the title and content fields, and both are properly disposed when the screen is removed to prevent memory leaks.
1class NoteEditorScreen extends StatefulWidget {2final Note? existingNote;34const NoteEditorScreen({this.existingNote});56@override7_NoteEditorScreenState createState() => _NoteEditorScreenState();8}910class _NoteEditorScreenState extends State<NoteEditorScreen> {11late TextEditingController _titleController;12late TextEditingController _contentController;1314@override15void initState() {16super.initState();17_titleController = TextEditingController(18text: widget.existingNote?.title ?? '',19);20_contentController = TextEditingController(21text: widget.existingNote?.content ?? '',22);23}2425@override26void dispose() {27_titleController.dispose();28_contentController.dispose();29super.dispose();30}3132@override33Widget build(BuildContext context) {34return Scaffold(35appBar: AppBar(36title: Text(widget.existingNote == null ? 'New Note' : 'Edit Note'),37actions: [38IconButton(39icon: Icon(Icons.save),40onPressed: _saveNote,41),42],43),44body: Padding(45padding: EdgeInsets.all(16),46child: Column(47children: [48TextField(49controller: _titleController,50decoration: InputDecoration(51hintText: 'Title',52border: InputBorder.none,53),54style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),55),56Expanded(57child: TextField(58controller: _contentController,59decoration: InputDecoration(60hintText: 'Start writing...',61border: InputBorder.none,62),63maxLines: null,64expands: true,65),66),67],68),69),70);71}72}
Notes apps look simple, but data quality decides long-term usability. Define lifecycle rules now:
This mindset prevents subtle bugs like notes jumping order unexpectedly or old records crashing parsing.
Build a notes app with local storage. Backend integration connects app actions to real user data and secure business workflows.
Connect each concept to real app features you can build.
Define data model and access rules before writing convenience helper methods.
Security and data integrity issues can damage user trust faster than UI bugs.
Security rules are part of architecture, not optional deployment polish.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
SharedPreferences works for small amounts of key-value data. For production notes apps with many entries, consider sqflite or hive for better performance and querying.
sqflite provides SQLite and Hive provides NoSQL key-value storage, both run locally on the device.
GridView displays items in a 2D grid (like Google Keep notes layout) using GridView.builder or GridView.count.
Use list.where() to filter notes whose title or content contains the search query string.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue