What pattern does this todo app use for state management?
The app uses ChangeNotifier with Provider for state management.
Build a complete todo list application
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 puts together everything you have learned so far into a real, usable application. You will build a fully functional todo list app that lets users add new tasks, mark them as complete, delete them with a swipe, and filter the list by status. Along the way you will practice working with models, Provider state management, ListView.builder, Dismissible widgets, dialogs, and local storage. By the end, you will have a complete app that you can actually use on your phone.
Features to build:
1// Todo model2class Todo {3final String id;4String title;5bool isCompleted;67Todo({8required this.id,9required this.title,10this.isCompleted = false,11});12}1314// Todo provider15class TodoProvider extends ChangeNotifier {16List<Todo> _todos = [];17String _filter = 'all'; // all, active, completed1819List<Todo> get todos {20switch (_filter) {21case 'active':22return _todos.where((t) => !t.isCompleted).toList();23case 'completed':24return _todos.where((t) => t.isCompleted).toList();25default:26return _todos;27}28}2930void addTodo(String title) {31_todos.add(Todo(32id: DateTime.now().toString(),33title: title,34));35notifyListeners();36}3738void toggleTodo(String id) {39final todo = _todos.firstWhere((t) => t.id == id);40todo.isCompleted = !todo.isCompleted;41notifyListeners();42}4344void deleteTodo(String id) {45_todos.removeWhere((t) => t.id == id);46notifyListeners();47}4849void setFilter(String filter) {50_filter = filter;51notifyListeners();52}53}
The main screen is where the user sees all their todos. It uses a Consumer widget to listen to the TodoProvider, which means the list automatically updates whenever a todo is added, deleted, or toggled. The AppBar contains a popup menu for switching between filter modes, and a FloatingActionButton at the bottom opens a dialog for creating new todos.
1class TodoScreen extends StatelessWidget {2@override3Widget build(BuildContext context) {4return Scaffold(5appBar: AppBar(6title: Text('My Todos'),7actions: [8PopupMenuButton<String>(9onSelected: (filter) {10context.read<TodoProvider>().setFilter(filter);11},12itemBuilder: (context) => [13PopupMenuItem(value: 'all', child: Text('All')),14PopupMenuItem(value: 'active', child: Text('Active')),15PopupMenuItem(value: 'completed', child: Text('Completed')),16],17),18],19),20body: Consumer<TodoProvider>(21builder: (context, provider, child) {22if (provider.todos.isEmpty) {23return Center(child: Text('No todos yet!'));24}25return ListView.builder(26itemCount: provider.todos.length,27itemBuilder: (context, index) {28final todo = provider.todos[index];29return TodoTile(todo: todo);30},31);32},33),34floatingActionButton: FloatingActionButton(35onPressed: () => _showAddDialog(context),36child: Icon(Icons.add),37),38);39}40}
Treat this app as a small production project, not a demo. Keep these responsibilities separate:
This separation gives you safer refactoring. For example, if you switch from SharedPreferences to Hive later, you should only touch the storage layer while provider and UI stay mostly unchanged.
Build a complete todo list application. This lesson adds one more building block for creating stable and user-friendly Flutter apps.
Connect each concept to real app features you can build.
After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.
Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.
Connect this lesson to separation of concerns so your codebase stays maintainable as it grows.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
The app uses ChangeNotifier with Provider for state management.
Dismissible wraps list items and provides swipe-to-dismiss functionality with onDismissed callback.
CheckboxListTile combines a Checkbox with a ListTile, perfect for todo items with title and completion status.
SharedPreferences for simple key-value or sqflite/Hive for complex data persistence across app restarts.
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