From e72240e47edb773ccc4e37e78eb4480e699d0e8d Mon Sep 17 00:00:00 2001 From: Adrito-M Date: Sun, 13 Feb 2022 21:34:27 +0530 Subject: [PATCH 1/2] passes all tests --- android/build.gradle | 2 +- lib/main.dart | 21 +-------- lib/models/todo_list.dart | 10 +++-- lib/screen/todo_screen.dart | 71 ++++++++++++++++++++++++++++-- lib/widgets/add_todo_dialogue.dart | 57 +++++++++++++++++++----- lib/widgets/todo_list_item.dart | 7 ++- pubspec.lock | 20 ++++----- 7 files changed, 138 insertions(+), 50 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..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..6036c09 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(); \ No newline at end of file diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index 70caa8b..536702e 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,80 @@ 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..6482a83 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,19 +9,53 @@ 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: From d7c22ac86efcf107442132b0bd9ff429b0b8be58 Mon Sep 17 00:00:00 2001 From: Adrito-M Date: Sun, 13 Feb 2022 23:54:30 +0530 Subject: [PATCH 2/2] minor bug fixes --- lib/models/todo_list.dart | 2 +- lib/screen/todo_screen.dart | 9 ++-- lib/widgets/add_todo_dialogue.dart | 78 +++++++++++++++--------------- 3 files changed, 43 insertions(+), 46 deletions(-) diff --git a/lib/models/todo_list.dart b/lib/models/todo_list.dart index 6036c09..8770a47 100644 --- a/lib/models/todo_list.dart +++ b/lib/models/todo_list.dart @@ -16,4 +16,4 @@ class TodoList { } } -//TodoList todoList = TodoList(); \ No newline at end of file +//TodoList todoList = TodoList(); diff --git a/lib/screen/todo_screen.dart b/lib/screen/todo_screen.dart index 536702e..da3ed9e 100644 --- a/lib/screen/todo_screen.dart +++ b/lib/screen/todo_screen.dart @@ -39,11 +39,10 @@ class _TodoScreenState extends State { child: const Icon(Icons.add), onPressed: () { showDialog( - context: context, - builder: (BuildContext context2) { - return const AddTodoDialogue(); - }, - ).then((value) { + context: context, + builder: (BuildContext context2) { + return const AddTodoDialogue(); + }).then((value) { setState(() { todoList.addTodo(value); }); diff --git a/lib/widgets/add_todo_dialogue.dart b/lib/widgets/add_todo_dialogue.dart index 6482a83..ff03daf 100644 --- a/lib/widgets/add_todo_dialogue.dart +++ b/lib/widgets/add_todo_dialogue.dart @@ -15,48 +15,46 @@ class _AddTodoDialogueState extends State { @override Widget build(BuildContext context) { 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; + 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); + Todo newTodo = + Todo(title: title, description: description); - controller1.clear(); - controller2.clear(); + controller1.clear(); + controller2.clear(); - Navigator.pop(context, newTodo); - } - }, - ), - ) - ], - ), - ), - ), - ); + Navigator.pop(context, newTodo); + } + }, + )) + ], + )))); } }