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..11a5652 100644 --- a/lib/models/todo_list.dart +++ b/lib/models/todo_list.dart @@ -1,17 +1,17 @@ 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); } } diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index 70caa8b..848df18 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -1,5 +1,7 @@ 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); @@ -11,16 +13,76 @@ class TodoScreen extends StatefulWidget { class _TodoScreenState extends State { TodoList todoList = TodoList(); + // final TextEditingController myController1 = TextEditingController(); + // final TextEditingController myController2 = TextEditingController(); + + Widget widgetbody = 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"), ), - //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 contextadd) { + return const AddTodoDialogue(); + }).then((value) { + setState(() { + todoList.addTodo(value); + }); + }); + }, + ), + body: todoList.allTodos().isNotEmpty + ? ListView.builder( + padding: const EdgeInsets.all(8.0), + itemCount: todoList.allTodos().length, + itemBuilder: (BuildContext context, int index) { + return GestureDetector( + onDoubleTap: () { + showDialog( + context: context, + builder: (BuildContext contextofdeletion) { + 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(contextofdeletion).pop(); + }); + }, + child: const Text("Yes")), + TextButton( + onPressed: () { + Navigator.of(contextofdeletion).pop(); + }, + child: const Text("No")) + ], + ); + }); + }, + child: TodoListItem( + index: index, + todo: todoList.allTodos()[index], + )); + }) + : widgetbody, ); } } diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index 29ccd08..ff95ec6 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,93 @@ class AddTodoDialogue extends StatefulWidget { } class _AddTodoDialogueState extends State { + final TextEditingController myController1 = TextEditingController(); + final TextEditingController myController2 = 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(12.0)), + child: SizedBox( + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + TextField( + controller: myController1, + decoration: const InputDecoration(labelText: "Title"), + ), + TextField( + controller: myController2, + decoration: + const InputDecoration(labelText: "Description"), + ), + TextButton( + onPressed: () { + setState(() { + if (myController1.text.isNotEmpty && + myController2.text.isNotEmpty) { + setState(() { + String title = myController1.text; + String description = myController2.text; + + Todo newincomingTodo = + Todo(title: title, description: description); + + myController1.clear(); + myController2.clear(); + + Navigator.pop(context, newincomingTodo); + }); + } + }); + }, + child: const Text("Submit"), + ) + ], + ))) + // width: 200, + // padding: const EdgeInsets.all(16), + // child: Column( + // mainAxisSize: MainAxisSize.min, + // children: [ + // TextField( + // controller: myController1, + // decoration: const InputDecoration(labelText: "Title"), + // ), + // TextField( + // controller: myController2, + // decoration: const InputDecoration(labelText: "Description"), + // ), + // const SizedBox(height: 18), + // SizedBox( + // child: TextButton( + // child: const Text("Submit"), + // onPressed: () { + // if (myController1.text.isNotEmpty && + // myController2.text.isNotEmpty) { + // setState(() { + // String title = myController1.text; + // String description = myController2.text; + + // Todo newTodo = Todo(title: title, description: description); + + // todoList.addTodo(newTodo); + + // myController1.clear(); + // myController2.clear(); + + // Navigator.of(context).pop(); + // }); + // } + // }, + // )) + // ], + // ), + ); } } diff --git a/lib/widgets/todo_list_item.dart b/lib/widgets/todo_list_item.dart index fe8536f..1d00fe2 100644 --- a/lib/widgets/todo_list_item.dart +++ b/lib/widgets/todo_list_item.dart @@ -8,7 +8,13 @@ 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: 20.0)), + subtitle: Text(todo.description), + leading: CircleAvatar( + child: Text("${index + 1}"), + backgroundColor: Colors.black, + ), + ); } } 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: