diff --git a/android/build.gradle b/android/build.gradle index 24047dc..4256f91 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.6.10' repositories { google() mavenCentral() diff --git a/lib/main.dart b/lib/main.dart index 30aa948..42371f4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,23 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:workshop_task/screen/todo_screen.dart'; void main() { - runApp(const MyApp()); -} - -class MyApp extends StatelessWidget { - const MyApp({Key key}) : super(key: key); - - // This widget is the root of your application. - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - // is not restarted. - primarySwatch: Colors.blue, - ), - //GO to correct screen. - home: Container(), - ); - } + runApp(const MaterialApp(home: TodoScreen())); } diff --git a/lib/models/todo_list.dart b/lib/models/todo_list.dart index c7c3b03..8770a47 100644 --- a/lib/models/todo_list.dart +++ b/lib/models/todo_list.dart @@ -1,17 +1,19 @@ import 'package:workshop_task/models/todo.dart'; class TodoList { - final List _allTodos = []; + final List _allTodos = []; List allTodos() { - //TODO:Add logic to complete + return _allTodos; } void addTodo(Todo todo) { - //TODO:Add logic to add a todo + _allTodos.add(todo); } void deleteTodo(Todo todo) { - //TODO:Add logic to delete todo + _allTodos.remove(todo); } } + +//TodoList todoList = TodoList(); diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index 70caa8b..da3ed9e 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -1,6 +1,9 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/models/todo_list.dart'; +import 'package:workshop_task/widgets/add_todo_dialogue.dart'; +import 'package:workshop_task/widgets/todo_list_item.dart'; + class TodoScreen extends StatefulWidget { const TodoScreen({Key key}) : super(key: key); @@ -9,18 +12,79 @@ class TodoScreen extends StatefulWidget { } class _TodoScreenState extends State { + // final TextEditingController controller1 = TextEditingController(); + // final TextEditingController controller2 = TextEditingController(); + TodoList todoList = TodoList(); + Widget wigbody = Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: const [ + Center( + child: Text("No Todos Added"), + ) + ], + ); + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("Your Todos"), ), + // ignore: todo //TODO: Add todo button with this icon => "+". - floatingActionButton: const FloatingActionButton(), - body: //TODO: Add list view displaying all todo. - Container(), + floatingActionButton: FloatingActionButton( + child: const Icon(Icons.add), + onPressed: () { + showDialog( + context: context, + builder: (BuildContext context2) { + return const AddTodoDialogue(); + }).then((value) { + setState(() { + todoList.addTodo(value); + }); + }); + }, + ), + body: todoList.allTodos().isNotEmpty + ? ListView.builder( + padding: const EdgeInsets.all(8), + itemCount: todoList.allTodos().length, + itemBuilder: (BuildContext context, int index) { + return GestureDetector( + onDoubleTap: () { + showDialog( + context: context, + builder: (BuildContext context_) { + return AlertDialog( + content: const Text( + "Are you sure you want to delete this Todo?"), + actions: [ + TextButton( + onPressed: () { + setState(() { + todoList.deleteTodo( + todoList.allTodos()[index]); + Navigator.of(context_).pop(); + }); + }, + child: const Text("Yes")), + TextButton( + onPressed: () { + Navigator.of(context_).pop(); + }, + child: const Text("No")) + ], + ); + }); + }, + child: TodoListItem( + todo: todoList.allTodos()[index], index: index)); + }) + : const Center(child: Text("No Todo's added")), ); } } diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index 29ccd08..ff03daf 100644 --- a/lib/widgets/add_todo_dialogue.dart +++ b/lib/widgets/add_todo_dialogue.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:workshop_task/models/todo.dart'; class AddTodoDialogue extends StatefulWidget { const AddTodoDialogue({Key key}) : super(key: key); @@ -8,20 +9,52 @@ class AddTodoDialogue extends StatefulWidget { } class _AddTodoDialogueState extends State { + final TextEditingController controller1 = TextEditingController(); + final TextEditingController controller2 = TextEditingController(); + @override Widget build(BuildContext context) { - return Container( - width: 200, - padding: const EdgeInsets.all(16), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - //TODO: Take input of title. and description. - TextField(), - TextField(), - TextButton(), - ], - ), - ); + return Dialog( + shape: + RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)), + child: SizedBox( + child: Padding( + padding: const EdgeInsets.all(15.0), + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + TextField( + controller: controller1, + decoration: const InputDecoration(labelText: "Title"), + ), + TextField( + controller: controller2, + decoration: + const InputDecoration(labelText: "Description"), + ), + const SizedBox(height: 20), + SizedBox( + child: TextButton( + child: const Text("SUBMIT"), + onPressed: () { + if (controller1.text.isNotEmpty && + controller2.text.isNotEmpty) { + String title = controller1.text; + String description = controller2.text; + + Todo newTodo = + Todo(title: title, description: description); + + controller1.clear(); + controller2.clear(); + + Navigator.pop(context, newTodo); + } + }, + )) + ], + )))); } } diff --git a/lib/widgets/todo_list_item.dart b/lib/widgets/todo_list_item.dart index fe8536f..239e0d5 100644 --- a/lib/widgets/todo_list_item.dart +++ b/lib/widgets/todo_list_item.dart @@ -8,7 +8,10 @@ class TodoListItem extends StatelessWidget { @override Widget build(BuildContext context) { - //TODO: display title and description of todo. - return Container(); + return ListTile( + title: Text(todo.title, style: const TextStyle(fontSize: 18.0)), + subtitle: Text(todo.description), + leading: CircleAvatar(child: Text("${index + 1}")), + ); } } diff --git a/pubspec.lock b/pubspec.lock index 8b519cf..7250f41 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -193,6 +193,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" meta: dependency: transitive description: @@ -228,13 +235,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.11.1" pool: dependency: transitive description: @@ -337,21 +337,21 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.17.12" + version: "1.19.5" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.3" + version: "0.4.8" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.2" + version: "0.4.9" typed_data: dependency: transitive description: