Skip to content
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
23 changes: 4 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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(const MaterialApp(
home: TodoScreen(),
));
}
8 changes: 4 additions & 4 deletions lib/models/todo_list.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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);
}
}
86 changes: 77 additions & 9 deletions lib/screen/todo_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +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);
Expand All @@ -9,18 +12,83 @@ class TodoScreen extends StatefulWidget {
}

class _TodoScreenState extends State<TodoScreen> {
TodoList todoList = TodoList();
final TextEditingController titlecontroller = TextEditingController();
final TextEditingController desccontroller = TextEditingController();

TodoList listitem = TodoList();
Widget wibody = 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"),
),
//TODO: Add todo button with this icon => "+".
floatingActionButton: const FloatingActionButton(),
body: //TODO: Add list view displaying all todo.
Container(),
);
appBar: AppBar(
title: const Text("Your Todos"),
),
floatingActionButton: FloatingActionButton(
child: const Icon(
Icons.add,
size: 35,
),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return const AddTodoDialogue();
}).then((value) {
setState(() {
{
listitem.addTodo(value);
}
});
});
}),
body: listitem.allTodos().isEmpty
? wibody
: ListView.builder(
itemBuilder: (context, 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: () {
Todo content = listitem.allTodos()[index];
Navigator.pop(context, content);
},
child: const Text("Yes")),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text("No"))
],
);
}).then((value) {
setState(() {
listitem.deleteTodo(value);
});
});
},
child: TodoListItem(
index: index + 1,
todo: listitem.allTodos()[index],
),
);
},
itemCount: listitem.allTodos().length,
));
}
}
58 changes: 45 additions & 13 deletions lib/widgets/add_todo_dialogue.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:workshop_task/models/todo_list.dart';
import 'package:workshop_task/models/todo.dart';

class AddTodoDialogue extends StatefulWidget {
const AddTodoDialogue({Key key}) : super(key: key);
Expand All @@ -8,20 +10,50 @@ class AddTodoDialogue extends StatefulWidget {
}

class _AddTodoDialogueState extends State<AddTodoDialogue> {
final TextEditingController titlecontroller = TextEditingController();
final TextEditingController desccontroller = TextEditingController();

int i = 0;
TodoList listItem = TodoList();
List<Widget> listWig = <Widget>[];

@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(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);

titlecontroller.clear();
desccontroller.clear();
Navigator.pop(context, content);
}
});
},
child: const Text("Submit"))
]))));
}
}
9 changes: 7 additions & 2 deletions lib/widgets/todo_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ 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),
leading: CircleAvatar(
child: Text("$index"),
),
);
}
}
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