From 7d0e1e066dbb4835d1045af07687c03a868b6a28 Mon Sep 17 00:00:00 2001 From: Deepshikha Sinha Date: Thu, 10 Feb 2022 23:18:19 +0530 Subject: [PATCH 1/5] A few changes --- android/build.gradle | 2 +- lib/main.dart | 6 ++-- lib/screen/todo_screen.dart | 21 +++++++++--- lib/widgets/add_todo_dialogue.dart | 53 ++++++++++++++++++++++-------- lib/widgets/todo_list_item.dart | 7 ++-- pubspec.lock | 20 +++++------ 6 files changed, 77 insertions(+), 32 deletions(-) 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..d421b83 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; +import 'package:workshop_task/screen/todo_screen.dart'; +import 'package:workshop_task/widgets/add_todo_dialogue.dart'; void main() { - runApp(const MyApp()); + runApp(MaterialApp(home: TodoScreen())); } class MyApp extends StatelessWidget { @@ -14,10 +16,10 @@ class MyApp extends StatelessWidget { title: 'Flutter Demo', theme: ThemeData( // is not restarted. + primarySwatch: Colors.blue, ), //GO to correct screen. - home: Container(), ); } } diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index 70caa8b..9331f83 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/models/todo_list.dart'; +import 'package:workshop_task/widgets/add_todo_dialogue.dart'; class TodoScreen extends StatefulWidget { + //Update user interface - use statefulwidgets const TodoScreen({Key key}) : super(key: key); @override @@ -15,12 +17,23 @@ class _TodoScreenState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text("Your Todos"), + title: const Text("My Tasks"), + ), + //Done//TODO: Add todo button with this icon => "+". + floatingActionButton: FloatingActionButton( + child: Icon(Icons.add, size: 50), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const AddTodoDialogue(), + )); + }, ), - //TODO: Add todo button with this icon => "+". - floatingActionButton: const FloatingActionButton(), body: //TODO: Add list view displaying all todo. - Container(), + Container( + child: Center(child: Text("Yay! No Pending Tasks")), + ), ); } } diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index 29ccd08..05e92da 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/screen/todo_screen.dart'; class AddTodoDialogue extends StatefulWidget { const AddTodoDialogue({Key key}) : super(key: key); @@ -8,20 +9,46 @@ class AddTodoDialogue extends StatefulWidget { } class _AddTodoDialogueState extends State { + final TextEditingController titlecontroller = TextEditingController(); + final TextEditingController desccontroller = 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(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 Task"), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const TodoScreen(), + )); + }, + ), + ], + ), + ))); } } diff --git a/lib/widgets/todo_list_item.dart b/lib/widgets/todo_list_item.dart index fe8536f..d03d248 100644 --- a/lib/widgets/todo_list_item.dart +++ b/lib/widgets/todo_list_item.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/models/todo.dart'; +import 'package:workshop_task/models/todo_list.dart'; class TodoListItem extends StatelessWidget { final Todo todo; @@ -8,7 +9,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: From 4a08f547b99856cb12f12259ae6be2e1a46d3a45 Mon Sep 17 00:00:00 2001 From: Deepshikha Sinha Date: Fri, 11 Feb 2022 14:45:00 +0530 Subject: [PATCH 2/5] Added functionlity of adding tasks --- lib/main.dart | 8 +-- lib/models/todo_list.dart | 6 +-- lib/screen/todo_screen.dart | 79 +++++++++++++++++++++--------- lib/widgets/add_todo_dialogue.dart | 33 +++++++++---- lib/widgets/todo_list_item.dart | 1 - 5 files changed, 84 insertions(+), 43 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index d421b83..ab4676d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,25 +1,19 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/screen/todo_screen.dart'; -import 'package:workshop_task/widgets/add_todo_dialogue.dart'; void main() { - runApp(MaterialApp(home: TodoScreen())); + 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. ); } } 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 9331f83..afd1f33 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -1,39 +1,72 @@ 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 { - //Update user interface - use statefulwidgets 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( + 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("My Tasks"), - ), - //Done//TODO: Add todo button with this icon => "+". - floatingActionButton: FloatingActionButton( - child: Icon(Icons.add, size: 50), - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const AddTodoDialogue(), - )); - }, - ), - body: //TODO: Add list view displaying all todo. - Container( - child: Center(child: Text("Yay! No Pending Tasks")), - ), - ); + var scaffold = Scaffold( + appBar: AppBar( + title: const Text("My Tasks"), + ), + floatingActionButton: FloatingActionButton( + child: const Icon(Icons.add, size: 50), + onPressed: () { + showDialog( + context: context, + builder: (context) { + return const Dialog( + child: AddTodoDialogue(), + ); + }).then((value) { + if (value != null) { + setState(() { + todoList.addTodo(value); + }); + } + }); + }, + ), + body: todoList.allTodos().isEmpty + ? taskdisplay + : ListView.builder( + itemBuilder: ((context, index) { + return TodoListItem( + index: index, + todo: todoList.allTodos()[index], + ); + }), + itemCount: todoList.allTodos().length, + ) /*ListView( + children: [ + GestureDetector( + child: ListTile( + title: Text(titlecontroller.text), + subtitle: Text(desccontroller.text), + ), + ) + ], + ),*/ + ); + return scaffold; } } diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index 05e92da..fe4308d 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'; import 'package:workshop_task/screen/todo_screen.dart'; class AddTodoDialogue extends StatefulWidget { @@ -11,6 +13,15 @@ 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 Dialog( @@ -38,15 +49,19 @@ class _AddTodoDialogueState extends State { controller: desccontroller, ), TextButton( - child: const Text("Add Task"), - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const TodoScreen(), - )); - }, - ), + 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 d03d248..b567b2c 100644 --- a/lib/widgets/todo_list_item.dart +++ b/lib/widgets/todo_list_item.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/models/todo.dart'; -import 'package:workshop_task/models/todo_list.dart'; class TodoListItem extends StatelessWidget { final Todo todo; From 36c43a19e7b843d65de5729332199271d0b55523 Mon Sep 17 00:00:00 2001 From: Deepshikha Sinha Date: Fri, 11 Feb 2022 23:40:23 +0530 Subject: [PATCH 3/5] Tried adding functionality --- lib/screen/todo_screen.dart | 48 ++++++++++++++++++++++-------- lib/widgets/add_todo_dialogue.dart | 2 -- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index afd1f33..e60dc34 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -29,7 +29,12 @@ class _TodoScreenState extends State { title: const Text("My Tasks"), ), floatingActionButton: FloatingActionButton( - child: const Icon(Icons.add, size: 50), + child: const Icon( + Icons.add, + size: 35, + color: Colors.black, + ), + backgroundColor: Colors.amber, onPressed: () { showDialog( context: context, @@ -41,6 +46,30 @@ class _TodoScreenState extends State { if (value != null) { setState(() { todoList.addTodo(value); + 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: () { + todoList.deleteTodo(value); + Navigator.of(context).pop(); + }), + TextButton( + child: const Text("NO"), + onPressed: () { + Navigator.of(context).pop(); + }) + ], + ); + }); + }); }); } }); @@ -56,17 +85,12 @@ class _TodoScreenState extends State { ); }), itemCount: todoList.allTodos().length, - ) /*ListView( - children: [ - GestureDetector( - child: ListTile( - title: Text(titlecontroller.text), - subtitle: Text(desccontroller.text), - ), - ) - ], - ),*/ - ); + )); return scaffold; } } + + +/* + + */ diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index fe4308d..6210d63 100644 --- a/lib/widgets/add_todo_dialogue.dart +++ b/lib/widgets/add_todo_dialogue.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/models/todo.dart'; import 'package:workshop_task/models/todo_list.dart'; -import 'package:workshop_task/screen/todo_screen.dart'; class AddTodoDialogue extends StatefulWidget { const AddTodoDialogue({Key key}) : super(key: key); @@ -57,7 +56,6 @@ class _AddTodoDialogueState extends State { Todo content = Todo( title: titlecontroller.text, description: desccontroller.text); - Navigator.of(context).pop(content); }); } From 0ce6046270ec515b806ceeb8555b2ecf6b2a1d87 Mon Sep 17 00:00:00 2001 From: Deepshikha Sinha Date: Sun, 13 Feb 2022 11:54:00 +0530 Subject: [PATCH 4/5] Made the required changes --- lib/screen/todo_screen.dart | 66 +++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index e60dc34..10228e9 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -14,6 +14,8 @@ 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")), @@ -46,30 +48,6 @@ class _TodoScreenState extends State { if (value != null) { setState(() { todoList.addTodo(value); - 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: () { - todoList.deleteTodo(value); - Navigator.of(context).pop(); - }), - TextButton( - child: const Text("NO"), - onPressed: () { - Navigator.of(context).pop(); - }) - ], - ); - }); - }); }); } }); @@ -79,9 +57,38 @@ class _TodoScreenState extends State { ? taskdisplay : ListView.builder( itemBuilder: ((context, index) { - return TodoListItem( - index: index, - todo: todoList.allTodos()[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, @@ -89,8 +96,3 @@ class _TodoScreenState extends State { return scaffold; } } - - -/* - - */ From 8601cf262a7c8a895554d1aa3473ee5e35cad4ec Mon Sep 17 00:00:00 2001 From: Deepshikha Sinha Date: Sun, 13 Feb 2022 23:24:15 +0530 Subject: [PATCH 5/5] Assignment submission --- lib/screen/todo_screen.dart | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index 10228e9..17dbbc1 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -41,9 +41,7 @@ class _TodoScreenState extends State { showDialog( context: context, builder: (context) { - return const Dialog( - child: AddTodoDialogue(), - ); + return const AddTodoDialogue(); }).then((value) { if (value != null) { setState(() { @@ -68,7 +66,7 @@ class _TodoScreenState extends State { "Are you sure you want to delete this task"), actions: [ TextButton( - child: const Text("YES"), + child: const Text("Yes"), onPressed: () { setState(() { todoList.deleteTodo( @@ -77,7 +75,7 @@ class _TodoScreenState extends State { }); }), TextButton( - child: const Text("NO"), + child: const Text("No"), onPressed: () { Navigator.of(context).pop(); })