diff --git a/android/build.gradle b/android/build.gradle index 58a8c74..713d7f6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/lib/main.dart b/lib/main.dart index 970cc61..997e5f6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -39,6 +39,12 @@ class _TodoListState extends State { _textFieldController.clear(); } + void _editTodoItem(Todo todo, String newName) { + setState(() { + todo.name = newName; + }); + } + void _handleTodoChange(Todo todo) { setState(() { todo.completed = !todo.completed; @@ -63,18 +69,19 @@ class _TodoListState extends State { return TodoItem( todo: todo, onTodoChanged: _handleTodoChange, - removeTodo: _deleteTodo); + removeTodo: _deleteTodo, + editTodo: _editTodoItem); }).toList(), ), floatingActionButton: FloatingActionButton( - onPressed: () => _displayDialog(), + onPressed: () => _displayAddDialog(), tooltip: 'Add a Todo', child: const Icon(Icons.add), ), ); } - Future _displayDialog() async { + Future _displayAddDialog() async { return showDialog( context: context, barrierDismissible: false, @@ -115,6 +122,49 @@ class _TodoListState extends State { }, ); } + + Future _displayEditDialog(Todo todo) async { + _textFieldController.text = todo.name; // Prefill with the current todo name + return showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Edit todo'), + content: TextField( + controller: _textFieldController, + decoration: const InputDecoration(hintText: 'Edit your todo'), + autofocus: true, + ), + actions: [ + OutlinedButton( + style: OutlinedButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + ), + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('Cancel'), + ), + ElevatedButton( + style: ElevatedButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + ), + onPressed: () { + Navigator.of(context).pop(); + _editTodoItem(todo, _textFieldController.text); + }, + child: const Text('Save'), + ), + ], + ); + }, + ); + } } class Todo { @@ -124,15 +174,17 @@ class Todo { } class TodoItem extends StatelessWidget { - TodoItem( - {required this.todo, - required this.onTodoChanged, - required this.removeTodo}) - : super(key: ObjectKey(todo)); + TodoItem({ + required this.todo, + required this.onTodoChanged, + required this.removeTodo, + required this.editTodo, + }) : super(key: ObjectKey(todo)); final Todo todo; final void Function(Todo todo) onTodoChanged; final void Function(Todo todo) removeTodo; + final void Function(Todo todo, String newName) editTodo; TextStyle? _getTextStyle(bool checked) { if (!checked) return null; @@ -163,10 +215,16 @@ class TodoItem extends StatelessWidget { ), IconButton( iconSize: 30, - icon: const Icon( - Icons.delete, - color: Colors.red, - ), + icon: const Icon(Icons.edit, color: Colors.blue), + alignment: Alignment.centerRight, + onPressed: () { + // Open edit dialog + _displayEditDialog(context, todo); + }, + ), + IconButton( + iconSize: 30, + icon: const Icon(Icons.delete, color: Colors.red), alignment: Alignment.centerRight, onPressed: () { removeTodo(todo); @@ -175,4 +233,9 @@ class TodoItem extends StatelessWidget { ]), ); } + + void _displayEditDialog(BuildContext context, Todo todo) { + // Pass the editTodo function from the parent widget to edit the todo + (context.findAncestorStateOfType<_TodoListState>())?._displayEditDialog(todo); + } } diff --git a/pubspec.lock b/pubspec.lock index 8ba7880..887ec2f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,10 +5,10 @@ packages: dependency: transitive description: name: async - sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" url: "https://pub.dev" source: hosted - version: "2.10.0" + version: "2.11.0" boolean_selector: dependency: transitive description: @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: characters - sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" clock: dependency: transitive description: @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.18.0" cupertino_icons: dependency: "direct main" description: @@ -75,14 +75,30 @@ packages: description: flutter source: sdk version: "0.0.0" - js: + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + url: "https://pub.dev" + source: hosted + version: "10.0.5" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + url: "https://pub.dev" + source: hosted + version: "3.0.5" + leak_tracker_testing: dependency: transitive description: - name: js - sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "0.6.5" + version: "3.0.1" lints: dependency: transitive description: @@ -95,34 +111,34 @@ packages: dependency: transitive description: name: matcher - sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.13" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.15.0" path: dependency: transitive description: name: path - sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -132,26 +148,26 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -172,10 +188,10 @@ packages: dependency: transitive description: name: test_api - sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.4.16" + version: "0.7.2" vector_math: dependency: transitive description: @@ -184,5 +200,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + url: "https://pub.dev" + source: hosted + version: "14.2.5" sdks: - dart: ">=2.19.5 <3.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54"