mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-11-08 20:50:04 +00:00
Add new flutter example of todo app with provider (#78)
This commit is contained in:
25
todo_list_using_provider/lib/notifiers/todo_list.dart
Normal file
25
todo_list_using_provider/lib/notifiers/todo_list.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_new_provider_todo/models/todo.dart';
|
||||
|
||||
/// This class represents a model
|
||||
/// that notify listeners when it has some changes
|
||||
class TodoList extends ChangeNotifier {
|
||||
List<Todo> _list = new List<Todo>();
|
||||
|
||||
List<Todo> get list => _list;
|
||||
|
||||
void add(Todo newItem) {
|
||||
this._list.add(newItem);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void remove(Todo removedItem) {
|
||||
this._list.remove(removedItem);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clearDoneItems() {
|
||||
this._list.removeWhere((Todo element) => element.done);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user