diff --git a/change_notifier_provider/lib/home/todo_list_view.dart b/change_notifier_provider/lib/home/todo_list_view.dart index ef34d820..c0f16e5a 100644 --- a/change_notifier_provider/lib/home/todo_list_view.dart +++ b/change_notifier_provider/lib/home/todo_list_view.dart @@ -22,47 +22,66 @@ class TodoListView extends StatelessWidget { itemBuilder: (context, index) { final todo = todos[index]; - return Dismissible( - key: ArchSampleKeys.todoItem(todo.id), - onDismissed: (_) => onRemove(context, todo), - child: ListTile( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (_) { - return DetailsScreen( - id: todo?.id, - onRemove: () { - Navigator.pop(context); - onRemove(context, todo); + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Dismissible( + key: ArchSampleKeys.todoItem(todo.id), + onDismissed: (_) => onRemove(context, todo), + child: ListTile( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) { + return DetailsScreen( + id: todo?.id, + onRemove: () { + Navigator.pop(context); + onRemove(context, todo); + }, + ); }, - ); + ), + ); + }, + leading: Checkbox( + key: ArchSampleKeys.todoItemCheckbox(todo.id), + value: todo.complete, + onChanged: (complete) { + Provider.of(context, listen: false) + .updateTodo(todo.copy(complete: complete)); }, ), - ); - }, - leading: Checkbox( - key: ArchSampleKeys.todoItemCheckbox(todo.id), - value: todo.complete, - onChanged: (complete) { - Provider.of(context, listen: false) - .updateTodo(todo.copy(complete: complete)); - }, - ), - title: Text( - todo.task, - key: ArchSampleKeys.todoItemTask(todo.id), - style: Theme.of(context).textTheme.title, - ), - subtitle: Text( - todo.note, - key: ArchSampleKeys.todoItemNote(todo.id), - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: Theme.of(context).textTheme.subhead, + title: Text( + todo.task, + key: ArchSampleKeys.todoItemTask(todo.id), + style: Theme.of(context).textTheme.title, + ), + subtitle: Text( + todo.note, + key: ArchSampleKeys.todoItemNote(todo.id), + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: Theme.of(context).textTheme.subhead, + ), + ), ), - ), + for(final person in todo.assignInfo.person) + ListTile( + title: Text('Person $person'), + trailing: IconButton( + icon: Icon(Icons.delete_forever), + onPressed: () { + Provider.of(context, listen: false) + .updateTodo(todo.copy(assignInfo: todo.assignInfo.copy(person: todo.assignInfo.person..remove(person)))); + /// CORRECT WAY +// Provider.of(context, listen: false) +// .updateTodo(todo.copy(assignInfo: todo.assignInfo.copy(person: List.of(todo.assignInfo.person)..remove(person)))); + }, + ), + ) + ], ); }, ); diff --git a/change_notifier_provider/lib/models.dart b/change_notifier_provider/lib/models.dart index 699321cb..9b10b755 100644 --- a/change_notifier_provider/lib/models.dart +++ b/change_notifier_provider/lib/models.dart @@ -14,13 +14,15 @@ class Todo { final String id; final String note; final String task; + final AssignInfo assignInfo; - Todo(this.task, {this.complete = false, this.note = '', String id}) - : id = id ?? Uuid().generateV4(); + Todo(this.task, {this.complete = false, this.note = '', String id, AssignInfo assignInfo}) + : id = id ?? Uuid().generateV4(), + assignInfo = assignInfo ?? AssignInfo(Person.values); @override int get hashCode => - complete.hashCode ^ task.hashCode ^ note.hashCode ^ id.hashCode; + complete.hashCode ^ task.hashCode ^ note.hashCode ^ assignInfo.hashCode ^ id.hashCode; @override bool operator ==(Object other) => @@ -28,13 +30,14 @@ class Todo { other is Todo && runtimeType == other.runtimeType && complete == other.complete && + assignInfo == other.assignInfo && task == other.task && note == other.note && id == other.id; @override String toString() { - return 'Todo{complete: $complete, task: $task, note: $note, id: $id}'; + return 'Todo{complete: $complete, task: $task, note: $note, assignInfo: $assignInfo, id: $id}'; } TodoEntity toEntity() { @@ -50,12 +53,28 @@ class Todo { ); } - Todo copy({String task, bool complete, String note, String id}) { + Todo copy({String task, bool complete, String note, String id, AssignInfo assignInfo}) { return Todo( task ?? this.task, complete: complete ?? this.complete, note: note ?? this.note, + assignInfo: assignInfo?.copy() ?? this.assignInfo?.copy(), id: id ?? this.id, ); } } + +class AssignInfo { + final List person; + + AssignInfo(this.person); + + AssignInfo copy({List person}) { + final newPerson = person ?? this.person; + return AssignInfo(newPerson != null ? List.of(newPerson) : null); + } +} + +enum Person { + sasha, masha, dasha +}