Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passes all tests #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
Expand Down
21 changes: 2 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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()));
}
10 changes: 6 additions & 4 deletions lib/models/todo_list.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import 'package:workshop_task/models/todo.dart';

class TodoList {
final List<Todo> _allTodos = [];
final List<Todo> _allTodos = <Todo>[];

List<Todo> 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();
70 changes: 67 additions & 3 deletions lib/screen/todo_screen.dart
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -9,18 +12,79 @@ class TodoScreen extends StatefulWidget {
}

class _TodoScreenState extends State<TodoScreen> {
// 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")),
);
}
}
59 changes: 46 additions & 13 deletions lib/widgets/add_todo_dialogue.dart
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -8,20 +9,52 @@ class AddTodoDialogue extends StatefulWidget {
}

class _AddTodoDialogueState extends State<AddTodoDialogue> {
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: <Widget>[
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);
}
},
))
],
))));
}
}
7 changes: 5 additions & 2 deletions lib/widgets/todo_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}")),
);
}
}
20 changes: 10 additions & 10 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down