From cf54fa495cee8b2b3e386eda5f4a2ab968c908ab Mon Sep 17 00:00:00 2001 From: ayushanand16 Date: Mon, 7 Feb 2022 13:15:28 +0530 Subject: [PATCH 1/6] Todo List --- lib/main.dart | 23 +---- lib/models/todo_list.dart | 7 +- lib/screen/todo_screen.dart | 133 +++++++++++++++++++++++++++-- lib/widgets/add_todo_dialogue.dart | 66 ++++++++++++-- lib/widgets/todo_list_item.dart | 10 ++- 5 files changed, 203 insertions(+), 36 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 30aa948..700c07c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,23 +1,8 @@ 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(MaterialApp( + home: TodoScreen(), + )); } diff --git a/lib/models/todo_list.dart b/lib/models/todo_list.dart index c7c3b03..45fd0de 100644 --- a/lib/models/todo_list.dart +++ b/lib/models/todo_list.dart @@ -1,17 +1,22 @@ import 'package:workshop_task/models/todo.dart'; +import 'package:workshop_task/widgets/todo_list_item.dart'; +import 'package:workshop_task/widgets/add_todo_dialogue.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..b944562 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); @@ -10,17 +12,130 @@ class TodoScreen extends StatefulWidget { class _TodoScreenState extends State { TodoList todoList = TodoList(); - + List LisWig = []; + final TextEditingController titlecontroller = TextEditingController(); + final TextEditingController desccontroller = TextEditingController(); + final GlobalKey _scaffoldKey = GlobalKey(); + Widget wigbody = Container( + child: 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(), - ); + key: _scaffoldKey, + appBar: AppBar( + title: const Text("Your Todos"), + ), + + //TODO: Add todo button with this icon => "+". + floatingActionButton: FloatingActionButton( + child: Icon(Icons.add), + onPressed: () { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5.0)), + child: Container( + height: 200, + child: Padding( + padding: const EdgeInsets.all(12.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + TextField( + controller: titlecontroller, + decoration: InputDecoration( + labelText: "Title", hintText: 'Title'), + ), + TextField( + controller: desccontroller, + decoration: InputDecoration( + labelText: "Description", + hintText: 'Description')), + SizedBox( + width: 320.0, + child: TextButton( + onPressed: () { + setState(() { + Navigator.of(context).pop(); + wigbody = ListView( + children: [ + GestureDetector( + child: ListTile( + title: Text(titlecontroller.text), + subtitle: + Text(desccontroller.text), + leading: CircleAvatar( + child: Text("1"), + ), + ), + onDoubleTap: () { + showDialog( + context: _scaffoldKey + .currentContext, + builder: (BuildContext + currentcontext) { + return AlertDialog( + content: Text( + "Are you sure you want to delete this todo?"), + actions: [ + TextButton( + onPressed: () { + setState(() { + titlecontroller + .clear(); + desccontroller + .clear(); + Navigator.of( + currentcontext) + .pop(); + wigbody = + Container( + child: Center( + child: Text( + "No Todos Added"), + ), + ); + }); + }, + child: Text("Yes")), + TextButton( + onPressed: () { + setState(() { + Navigator.of( + currentcontext) + .pop(); + }); + }, + child: Text("No")) + ], + ); + }); + }, + ) + ], + ); + }); + }, + child: Text( + "Submit", + style: TextStyle(color: Colors.blue), + ), + ), + ) + ], + ), + ), + ), + ); + }); + }), + body: //TODO: Add list view displaying all todo. + wigbody); } } diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index 29ccd08..2666dd9 100644 --- a/lib/widgets/add_todo_dialogue.dart +++ b/lib/widgets/add_todo_dialogue.dart @@ -1,4 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:workshop_task/models/todo_list.dart'; +import 'package:workshop_task/models/todo.dart'; +import 'package:workshop_task/screen/todo_screen.dart'; +import 'package:workshop_task/widgets/todo_list_item.dart'; class AddTodoDialogue extends StatefulWidget { const AddTodoDialogue({Key key}) : super(key: key); @@ -8,18 +12,70 @@ class AddTodoDialogue extends StatefulWidget { } class _AddTodoDialogueState extends State { + final TextEditingController titlecontroller = TextEditingController(); + final TextEditingController desccontroller = TextEditingController(); + var i = 0; + List LisWig = []; @override Widget build(BuildContext context) { return Container( width: 200, - padding: const EdgeInsets.all(16), + padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0), child: Column( mainAxisSize: MainAxisSize.min, - children: [ + mainAxisAlignment: MainAxisAlignment.center, + children: [ //TODO: Take input of title. and description. - TextField(), - TextField(), - TextButton(), + Material( + child: Container( + width: 2000, + padding: const EdgeInsets.symmetric( + vertical: 4.0, horizontal: 4.0), + child: TextField( + controller: titlecontroller, + decoration: + InputDecoration(hintText: "Title", labelText: "Title"), + ))), + Material( + child: Container( + width: 2000, + padding: const EdgeInsets.symmetric( + vertical: 4.0, horizontal: 4.0), + child: TextField( + controller: desccontroller, + decoration: InputDecoration( + hintText: "Description", labelText: "Description"), + ))), + Material( + child: Container( + width: 2000, + height: 60, + padding: const EdgeInsets.symmetric( + vertical: 4.0, horizontal: 4.0), + child: TextButton( + onPressed: () { + setState(() { + Navigator.of(context).pop(); + + Todo ListItem = Todo( + title: titlecontroller.text.toString(), + description: desccontroller.text.toString()); + + var todoList = TodoList(); + todoList.addTodo(ListItem); + + TodoListItem WigItem = TodoListItem( + todo: todoList.allTodos()[i], + index: i + 1, + ); + + LisWig.add(WigItem); + }); + }, + child: Text('Submit', + style: TextStyle( + fontWeight: FontWeight.bold, + ))))) ], ), ); diff --git a/lib/widgets/todo_list_item.dart b/lib/widgets/todo_list_item.dart index fe8536f..3754550 100644 --- a/lib/widgets/todo_list_item.dart +++ b/lib/widgets/todo_list_item.dart @@ -1,14 +1,20 @@ 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'; class TodoListItem extends StatelessWidget { final Todo todo; final int index; - const TodoListItem({Key key, this.todo, this.index}) : super(key: key); + TodoListItem({Key key, this.todo, this.index}) : super(key: key); @override Widget build(BuildContext context) { //TODO: display title and description of todo. - return Container(); + + return ListTile( + title: Text(todo.title), + subtitle: Text(todo.description), + ); } } From fc898a1fd1b8e4ce00a3780aded397220c0b7bfd Mon Sep 17 00:00:00 2001 From: ayushanand16 Date: Tue, 8 Feb 2022 14:21:23 +0530 Subject: [PATCH 2/6] Remove Problems --- lib/main.dart | 2 +- lib/models/todo_list.dart | 5 --- lib/screen/todo_screen.dart | 53 +++++++++++++++--------------- lib/widgets/add_todo_dialogue.dart | 21 ++++++------ lib/widgets/todo_list_item.dart | 6 +--- 5 files changed, 39 insertions(+), 48 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 700c07c..fadbee0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/screen/todo_screen.dart'; void main() { - runApp(MaterialApp( + runApp(const MaterialApp( home: TodoScreen(), )); } diff --git a/lib/models/todo_list.dart b/lib/models/todo_list.dart index 45fd0de..11a5652 100644 --- a/lib/models/todo_list.dart +++ b/lib/models/todo_list.dart @@ -1,22 +1,17 @@ import 'package:workshop_task/models/todo.dart'; -import 'package:workshop_task/widgets/todo_list_item.dart'; -import 'package:workshop_task/widgets/add_todo_dialogue.dart'; 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 b944562..ec1e6a7 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -1,7 +1,5 @@ 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); @@ -12,15 +10,18 @@ class TodoScreen extends StatefulWidget { class _TodoScreenState extends State { TodoList todoList = TodoList(); - List LisWig = []; + List lisWig = []; final TextEditingController titlecontroller = TextEditingController(); final TextEditingController desccontroller = TextEditingController(); final GlobalKey _scaffoldKey = GlobalKey(); - Widget wigbody = Container( - child: Center( - child: Text("No Todos Added"), - ), + Widget wigbody = Row( + children: const [ + Center( + child: Text("No Todos Added"), + ) + ], ); + @override Widget build(BuildContext context) { return Scaffold( @@ -28,10 +29,8 @@ class _TodoScreenState extends State { appBar: AppBar( title: const Text("Your Todos"), ), - - //TODO: Add todo button with this icon => "+". floatingActionButton: FloatingActionButton( - child: Icon(Icons.add), + child: const Icon(Icons.add), onPressed: () { showDialog( context: context, @@ -39,7 +38,7 @@ class _TodoScreenState extends State { return Dialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(5.0)), - child: Container( + child: SizedBox( height: 200, child: Padding( padding: const EdgeInsets.all(12.0), @@ -49,12 +48,12 @@ class _TodoScreenState extends State { children: [ TextField( controller: titlecontroller, - decoration: InputDecoration( + decoration: const InputDecoration( labelText: "Title", hintText: 'Title'), ), TextField( controller: desccontroller, - decoration: InputDecoration( + decoration: const InputDecoration( labelText: "Description", hintText: 'Description')), SizedBox( @@ -70,7 +69,7 @@ class _TodoScreenState extends State { title: Text(titlecontroller.text), subtitle: Text(desccontroller.text), - leading: CircleAvatar( + leading: const CircleAvatar( child: Text("1"), ), ), @@ -81,7 +80,7 @@ class _TodoScreenState extends State { builder: (BuildContext currentcontext) { return AlertDialog( - content: Text( + content: const Text( "Are you sure you want to delete this todo?"), actions: [ TextButton( @@ -94,16 +93,18 @@ class _TodoScreenState extends State { Navigator.of( currentcontext) .pop(); - wigbody = - Container( - child: Center( - child: Text( - "No Todos Added"), - ), + wigbody = Row( + children: const [ + Center( + child: Text( + "No Todos Added"), + ) + ], ); }); }, - child: Text("Yes")), + child: const Text( + "Yes")), TextButton( onPressed: () { setState(() { @@ -112,7 +113,8 @@ class _TodoScreenState extends State { .pop(); }); }, - child: Text("No")) + child: const Text( + "No")) ], ); }); @@ -122,7 +124,7 @@ class _TodoScreenState extends State { ); }); }, - child: Text( + child: const Text( "Submit", style: TextStyle(color: Colors.blue), ), @@ -135,7 +137,6 @@ class _TodoScreenState extends State { ); }); }), - body: //TODO: Add list view displaying all todo. - wigbody); + body: wigbody); } } diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index 2666dd9..6186a02 100644 --- a/lib/widgets/add_todo_dialogue.dart +++ b/lib/widgets/add_todo_dialogue.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/models/todo_list.dart'; import 'package:workshop_task/models/todo.dart'; -import 'package:workshop_task/screen/todo_screen.dart'; + import 'package:workshop_task/widgets/todo_list_item.dart'; class AddTodoDialogue extends StatefulWidget { @@ -15,7 +15,7 @@ class _AddTodoDialogueState extends State { final TextEditingController titlecontroller = TextEditingController(); final TextEditingController desccontroller = TextEditingController(); var i = 0; - List LisWig = []; + List lisWig = []; @override Widget build(BuildContext context) { return Container( @@ -25,7 +25,6 @@ class _AddTodoDialogueState extends State { mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: [ - //TODO: Take input of title. and description. Material( child: Container( width: 2000, @@ -33,8 +32,8 @@ class _AddTodoDialogueState extends State { vertical: 4.0, horizontal: 4.0), child: TextField( controller: titlecontroller, - decoration: - InputDecoration(hintText: "Title", labelText: "Title"), + decoration: const InputDecoration( + hintText: "Title", labelText: "Title"), ))), Material( child: Container( @@ -43,7 +42,7 @@ class _AddTodoDialogueState extends State { vertical: 4.0, horizontal: 4.0), child: TextField( controller: desccontroller, - decoration: InputDecoration( + decoration: const InputDecoration( hintText: "Description", labelText: "Description"), ))), Material( @@ -57,22 +56,22 @@ class _AddTodoDialogueState extends State { setState(() { Navigator.of(context).pop(); - Todo ListItem = Todo( + Todo listItem = Todo( title: titlecontroller.text.toString(), description: desccontroller.text.toString()); var todoList = TodoList(); - todoList.addTodo(ListItem); + todoList.addTodo(listItem); - TodoListItem WigItem = TodoListItem( + TodoListItem wigItem = TodoListItem( todo: todoList.allTodos()[i], index: i + 1, ); - LisWig.add(WigItem); + lisWig.add(wigItem); }); }, - child: Text('Submit', + child: const Text('Submit', style: TextStyle( fontWeight: FontWeight.bold, ))))) diff --git a/lib/widgets/todo_list_item.dart b/lib/widgets/todo_list_item.dart index 3754550..b567b2c 100644 --- a/lib/widgets/todo_list_item.dart +++ b/lib/widgets/todo_list_item.dart @@ -1,17 +1,13 @@ 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'; class TodoListItem extends StatelessWidget { final Todo todo; final int index; - TodoListItem({Key key, this.todo, this.index}) : super(key: key); + const TodoListItem({Key key, this.todo, this.index}) : super(key: key); @override Widget build(BuildContext context) { - //TODO: display title and description of todo. - return ListTile( title: Text(todo.title), subtitle: Text(todo.description), From c75a71384626652a5e38167fbcf6850a51bdad59 Mon Sep 17 00:00:00 2001 From: ayushanand16 Date: Wed, 9 Feb 2022 13:51:31 +0530 Subject: [PATCH 3/6] Todo Screen Remove Dialogue Box Error --- lib/screen/todo_screen.dart | 130 +++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 62 deletions(-) diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index ec1e6a7..01111e9 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:workshop_task/models/todo.dart'; import 'package:workshop_task/models/todo_list.dart'; class TodoScreen extends StatefulWidget { @@ -10,6 +11,7 @@ class TodoScreen extends StatefulWidget { class _TodoScreenState extends State { TodoList todoList = TodoList(); + final List _allTodos = []; List lisWig = []; final TextEditingController titlecontroller = TextEditingController(); final TextEditingController desccontroller = TextEditingController(); @@ -60,69 +62,73 @@ class _TodoScreenState extends State { width: 320.0, child: TextButton( onPressed: () { - setState(() { - Navigator.of(context).pop(); - wigbody = ListView( - children: [ - GestureDetector( - child: ListTile( - title: Text(titlecontroller.text), - subtitle: - Text(desccontroller.text), - leading: const CircleAvatar( - child: Text("1"), + if (titlecontroller.text.isNotEmpty && + desccontroller.text.isNotEmpty) { + setState(() { + Navigator.of(context).pop(); + wigbody = ListView( + children: [ + GestureDetector( + child: ListTile( + title: + Text(titlecontroller.text), + subtitle: + Text(desccontroller.text), + leading: const CircleAvatar( + child: Text("1"), + ), ), - ), - onDoubleTap: () { - showDialog( - context: _scaffoldKey - .currentContext, - builder: (BuildContext - currentcontext) { - return AlertDialog( - content: const Text( - "Are you sure you want to delete this todo?"), - actions: [ - TextButton( - onPressed: () { - setState(() { - titlecontroller - .clear(); - desccontroller - .clear(); - Navigator.of( - currentcontext) - .pop(); - wigbody = Row( - children: const [ - Center( - child: Text( - "No Todos Added"), - ) - ], - ); - }); - }, - child: const Text( - "Yes")), - TextButton( - onPressed: () { - setState(() { - Navigator.of( - currentcontext) - .pop(); - }); - }, - child: const Text( - "No")) - ], - ); - }); - }, - ) - ], - ); - }); + onDoubleTap: () { + showDialog( + context: _scaffoldKey + .currentContext, + builder: (BuildContext + currentcontext) { + return AlertDialog( + content: const Text( + "Are you sure you want to delete this todo?"), + actions: [ + TextButton( + onPressed: () { + setState(() { + titlecontroller + .clear(); + desccontroller + .clear(); + Navigator.of( + currentcontext) + .pop(); + wigbody = Row( + children: const [ + Center( + child: Text( + "No Todos Added"), + ) + ], + ); + }); + }, + child: const Text( + "Yes")), + TextButton( + onPressed: () { + setState(() { + Navigator.of( + currentcontext) + .pop(); + }); + }, + child: const Text( + "No")) + ], + ); + }); + }, + ) + ], + ); + }); + } }, child: const Text( "Submit", From b3c9c726bafa9a9e389bf9d104323ddf5a145aa9 Mon Sep 17 00:00:00 2001 From: ayushanand16 Date: Wed, 9 Feb 2022 14:22:16 +0530 Subject: [PATCH 4/6] Flutter analyzer issue solve --- lib/screen/todo_screen.dart | 13 ++-- lib/widgets/add_todo_dialogue.dart | 101 +++++++++++------------------ 2 files changed, 46 insertions(+), 68 deletions(-) diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index 01111e9..6facdc4 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -1,6 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:workshop_task/models/todo.dart'; -import 'package:workshop_task/models/todo_list.dart'; class TodoScreen extends StatefulWidget { const TodoScreen({Key key}) : super(key: key); @@ -10,13 +8,12 @@ class TodoScreen extends StatefulWidget { } class _TodoScreenState extends State { - TodoList todoList = TodoList(); - final List _allTodos = []; - List lisWig = []; final TextEditingController titlecontroller = TextEditingController(); final TextEditingController desccontroller = TextEditingController(); final GlobalKey _scaffoldKey = GlobalKey(); Widget wigbody = Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, children: const [ Center( child: Text("No Todos Added"), @@ -99,6 +96,12 @@ class _TodoScreenState extends State { currentcontext) .pop(); wigbody = Row( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, children: const [ Center( child: Text( diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index 6186a02..d4c11b2 100644 --- a/lib/widgets/add_todo_dialogue.dart +++ b/lib/widgets/add_todo_dialogue.dart @@ -2,8 +2,6 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/models/todo_list.dart'; import 'package:workshop_task/models/todo.dart'; -import 'package:workshop_task/widgets/todo_list_item.dart'; - class AddTodoDialogue extends StatefulWidget { const AddTodoDialogue({Key key}) : super(key: key); @@ -14,69 +12,46 @@ class AddTodoDialogue extends StatefulWidget { class _AddTodoDialogueState extends State { final TextEditingController titlecontroller = TextEditingController(); final TextEditingController desccontroller = TextEditingController(); - var i = 0; + int i = 0; + TodoList listItem = TodoList(); List lisWig = []; @override Widget build(BuildContext context) { - return Container( - width: 200, - padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Material( - child: Container( - width: 2000, - padding: const EdgeInsets.symmetric( - vertical: 4.0, horizontal: 4.0), - child: TextField( - controller: titlecontroller, - decoration: const InputDecoration( - hintText: "Title", labelText: "Title"), - ))), - Material( - child: Container( - width: 2000, - padding: const EdgeInsets.symmetric( - vertical: 4.0, horizontal: 4.0), - child: TextField( - controller: desccontroller, - decoration: const InputDecoration( - hintText: "Description", labelText: "Description"), - ))), - Material( - child: Container( - width: 2000, - height: 60, - padding: const EdgeInsets.symmetric( - vertical: 4.0, horizontal: 4.0), - child: TextButton( - onPressed: () { - setState(() { - Navigator.of(context).pop(); - - Todo listItem = Todo( - title: titlecontroller.text.toString(), - description: desccontroller.text.toString()); - - var todoList = TodoList(); - todoList.addTodo(listItem); - - TodoListItem wigItem = TodoListItem( - todo: todoList.allTodos()[i], - index: i + 1, - ); - - lisWig.add(wigItem); - }); - }, - child: const Text('Submit', - style: TextStyle( - fontWeight: FontWeight.bold, - ))))) - ], - ), - ); + return Dialog( + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)), + child: SizedBox( + height: 200, + child: Padding( + padding: const EdgeInsets.all(12.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + TextField( + controller: titlecontroller, + decoration: const InputDecoration(labelText: "Title"), + ), + TextField( + controller: desccontroller, + decoration: + const InputDecoration(labelText: "Description"), + ), + TextButton( + onPressed: () { + setState(() { + if (titlecontroller.text.isNotEmpty && + desccontroller.text.isNotEmpty) { + Todo content = Todo( + title: titlecontroller.text, + description: desccontroller.text); + + listItem.addTodo(content); + titlecontroller.clear(); + desccontroller.clear(); + } + }); + }, + child: const Text("Submit")) + ])))); } } From 8827143bc0f3ee5c11a1a4740370002905601c37 Mon Sep 17 00:00:00 2001 From: ayushanand16 Date: Sat, 12 Feb 2022 17:32:44 +0530 Subject: [PATCH 5/6] Use AddtoDoDialogue and ToDoListItem --- lib/main.dart | 2 + lib/screen/todo_screen.dart | 168 ++++++++++------------------- lib/widgets/add_todo_dialogue.dart | 2 +- lib/widgets/todo_list_item.dart | 3 + 4 files changed, 60 insertions(+), 115 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index fadbee0..19aa587 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/screen/todo_screen.dart'; +import 'package:workshop_task/models/todo.dart'; +import 'package:workshop_task/models/todo_list.dart'; void main() { runApp(const MaterialApp( diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index 6facdc4..7b6cff7 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -1,4 +1,8 @@ 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); @@ -10,7 +14,8 @@ class TodoScreen extends StatefulWidget { class _TodoScreenState extends State { final TextEditingController titlecontroller = TextEditingController(); final TextEditingController desccontroller = TextEditingController(); - final GlobalKey _scaffoldKey = GlobalKey(); + + TodoList doList = TodoList(); Widget wigbody = Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, @@ -24,7 +29,6 @@ class _TodoScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - key: _scaffoldKey, appBar: AppBar( title: const Text("Your Todos"), ), @@ -34,118 +38,54 @@ class _TodoScreenState extends State { showDialog( context: context, builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5.0)), - child: SizedBox( - height: 200, - child: Padding( - padding: const EdgeInsets.all(12.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - TextField( - controller: titlecontroller, - decoration: const InputDecoration( - labelText: "Title", hintText: 'Title'), - ), - TextField( - controller: desccontroller, - decoration: const InputDecoration( - labelText: "Description", - hintText: 'Description')), - SizedBox( - width: 320.0, - child: TextButton( - onPressed: () { - if (titlecontroller.text.isNotEmpty && - desccontroller.text.isNotEmpty) { - setState(() { - Navigator.of(context).pop(); - wigbody = ListView( - children: [ - GestureDetector( - child: ListTile( - title: - Text(titlecontroller.text), - subtitle: - Text(desccontroller.text), - leading: const CircleAvatar( - child: Text("1"), - ), - ), - onDoubleTap: () { - showDialog( - context: _scaffoldKey - .currentContext, - builder: (BuildContext - currentcontext) { - return AlertDialog( - content: const Text( - "Are you sure you want to delete this todo?"), - actions: [ - TextButton( - onPressed: () { - setState(() { - titlecontroller - .clear(); - desccontroller - .clear(); - Navigator.of( - currentcontext) - .pop(); - wigbody = Row( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: const [ - Center( - child: Text( - "No Todos Added"), - ) - ], - ); - }); - }, - child: const Text( - "Yes")), - TextButton( - onPressed: () { - setState(() { - Navigator.of( - currentcontext) - .pop(); - }); - }, - child: const Text( - "No")) - ], - ); - }); - }, - ) - ], - ); - }); - } - }, - child: const Text( - "Submit", - style: TextStyle(color: Colors.blue), - ), - ), - ) - ], - ), - ), - ), - ); - }); + return const AddTodoDialogue(); + }).then((value) { + setState(() { + { + doList.addTodo(value); + } + }); + }); }), - body: wigbody); + body: doList.allTodos().isEmpty + ? wigbody + : ListView.builder( + itemBuilder: (context, index) { + return GestureDetector( + onDoubleTap: () { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + content: Text( + "Are you sure you want to delete this todo"), + actions: [ + TextButton( + onPressed: () { + Todo content = doList.allTodos()[index]; + Navigator.pop(context, content); + }, + child: Text("Yes")), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: Text("No")) + ], + ); + }).then((value) { + setState(() { + doList.deleteTodo(value); + }); + }); + }, + child: TodoListItem( + index: index + 1, + todo: doList.allTodos()[index], + ), + ); + }, + itemCount: doList.allTodos().length, + )); } } diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index d4c11b2..b700139 100644 --- a/lib/widgets/add_todo_dialogue.dart +++ b/lib/widgets/add_todo_dialogue.dart @@ -45,9 +45,9 @@ class _AddTodoDialogueState extends State { title: titlecontroller.text, description: desccontroller.text); - listItem.addTodo(content); titlecontroller.clear(); desccontroller.clear(); + Navigator.pop(context, content); } }); }, diff --git a/lib/widgets/todo_list_item.dart b/lib/widgets/todo_list_item.dart index b567b2c..83d4217 100644 --- a/lib/widgets/todo_list_item.dart +++ b/lib/widgets/todo_list_item.dart @@ -11,6 +11,9 @@ class TodoListItem extends StatelessWidget { return ListTile( title: Text(todo.title), subtitle: Text(todo.description), + leading: CircleAvatar( + child: Text("$index"), + ), ); } } From 2fc72d6e15b61e128c42976c8330afb2be6d25a6 Mon Sep 17 00:00:00 2001 From: ayushanand16 Date: Sat, 12 Feb 2022 17:37:38 +0530 Subject: [PATCH 6/6] Flutter Analyze corrected --- lib/main.dart | 2 -- lib/screen/todo_screen.dart | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 19aa587..fadbee0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,5 @@ import 'package:flutter/material.dart'; import 'package:workshop_task/screen/todo_screen.dart'; -import 'package:workshop_task/models/todo.dart'; -import 'package:workshop_task/models/todo_list.dart'; void main() { runApp(const MaterialApp( diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index 7b6cff7..f29fd26 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -57,7 +57,7 @@ class _TodoScreenState extends State { context: context, builder: (BuildContext context) { return AlertDialog( - content: Text( + content: const Text( "Are you sure you want to delete this todo"), actions: [ TextButton( @@ -65,12 +65,12 @@ class _TodoScreenState extends State { Todo content = doList.allTodos()[index]; Navigator.pop(context, content); }, - child: Text("Yes")), + child: const Text("Yes")), TextButton( onPressed: () { Navigator.pop(context); }, - child: Text("No")) + child: const Text("No")) ], ); }).then((value) {