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..ab4676d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,23 +1,19 @@ import 'package:flutter/material.dart'; +import 'package:workshop_task/screen/todo_screen.dart'; void main() { - runApp(const MyApp()); + runApp(const MaterialApp(home: TodoScreen())); } 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(), ); } } diff --git a/lib/models/todo_list.dart b/lib/models/todo_list.dart index c7c3b03..12503f9 100644 --- a/lib/models/todo_list.dart +++ b/lib/models/todo_list.dart @@ -4,14 +4,14 @@ class TodoList { 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..17dbbc1 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -1,26 +1,96 @@ import 'package:flutter/material.dart'; +import 'package:workshop_task/models/todo.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); - @override _TodoScreenState createState() => _TodoScreenState(); } class _TodoScreenState extends State { + final TextEditingController titlecontroller = TextEditingController(); + final TextEditingController desccontroller = TextEditingController(); + Widget taskdisplay = Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: const [ + Center( + child: Center(child: Text("Yay! No Pending Tasks")), + ) + ], + ); TodoList todoList = TodoList(); - + Todo content; @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(), - ); + var scaffold = Scaffold( + appBar: AppBar( + title: const Text("My Tasks"), + ), + floatingActionButton: FloatingActionButton( + child: const Icon( + Icons.add, + size: 35, + color: Colors.black, + ), + backgroundColor: Colors.amber, + onPressed: () { + showDialog( + context: context, + builder: (context) { + return const AddTodoDialogue(); + }).then((value) { + if (value != null) { + setState(() { + todoList.addTodo(value); + }); + } + }); + }, + ), + body: todoList.allTodos().isEmpty + ? taskdisplay + : ListView.builder( + itemBuilder: ((context, index) { + return GestureDetector( + onDoubleTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text("DELETE TASK"), + content: const Text( + "Are you sure you want to delete this task"), + actions: [ + TextButton( + child: const Text("Yes"), + onPressed: () { + setState(() { + todoList.deleteTodo( + todoList.allTodos()[index]); + Navigator.of(context).pop(); + }); + }), + TextButton( + child: const Text("No"), + onPressed: () { + Navigator.of(context).pop(); + }) + ], + ); + }); + }, + child: TodoListItem( + index: index, + todo: todoList.allTodos()[index], + ), + ); + }), + itemCount: todoList.allTodos().length, + )); + return scaffold; } } diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index 29ccd08..6210d63 100644 --- a/lib/widgets/add_todo_dialogue.dart +++ b/lib/widgets/add_todo_dialogue.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:workshop_task/models/todo.dart'; +import 'package:workshop_task/models/todo_list.dart'; class AddTodoDialogue extends StatefulWidget { const AddTodoDialogue({Key key}) : super(key: key); @@ -8,20 +10,58 @@ class AddTodoDialogue extends StatefulWidget { } class _AddTodoDialogueState extends State { + final TextEditingController titlecontroller = TextEditingController(); + final TextEditingController desccontroller = TextEditingController(); + TodoList listItem = TodoList(); + Widget taskdisplay = Row( + children: const [ + Center( + child: Center(child: Text("Yay! No Pending Tasks")), + ) + ], + ); + @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(5.0)), + child: SizedBox( + height: 300, + width: 300, + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextField( + decoration: const InputDecoration( + border: OutlineInputBorder(), + hintText: "Enter title", + ), + controller: titlecontroller, + ), + TextField( + decoration: const InputDecoration( + border: OutlineInputBorder(), + hintText: "Enter description", + ), + controller: desccontroller, + ), + TextButton( + child: const Text("Add"), + onPressed: () { + if (titlecontroller.text.isNotEmpty && + desccontroller.text.isNotEmpty) { + setState(() { + Todo content = Todo( + title: titlecontroller.text, + description: desccontroller.text); + Navigator.of(context).pop(content); + }); + } + }), + ], + ), + ))); } } diff --git a/lib/widgets/todo_list_item.dart b/lib/widgets/todo_list_item.dart index fe8536f..b567b2c 100644 --- a/lib/widgets/todo_list_item.dart +++ b/lib/widgets/todo_list_item.dart @@ -8,7 +8,9 @@ class TodoListItem extends StatelessWidget { @override Widget build(BuildContext context) { - //TODO: display title and description of todo. - return Container(); + return ListTile( + title: Text(todo.title), + subtitle: Text(todo.description), + ); } } 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: