-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1af63fa
commit 55ad2c5
Showing
11 changed files
with
240 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:todolistapp_updates/models/task_data.dart'; | ||
class AddTaskScreen extends StatelessWidget { | ||
final Function addTaskCallback; | ||
const AddTaskScreen ({Key? key, required this.addTaskCallback}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
String newTaskTitle=''; | ||
return Container( | ||
color:const Color(0xff757575), | ||
child: Container( | ||
padding: const EdgeInsets.all(20.0), | ||
decoration: const BoxDecoration( | ||
color: Colors.white, | ||
borderRadius: BorderRadius.only( | ||
topLeft: Radius.circular(20.0), | ||
topRight: Radius.circular(20.0), | ||
), | ||
), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: <Widget>[ | ||
const Center( | ||
child: Text( | ||
'Add Text', | ||
style: TextStyle( | ||
fontSize: 30.0, | ||
color:Colors.lightBlueAccent | ||
), | ||
), | ||
), | ||
TextField( | ||
autofocus: true, | ||
textAlign: TextAlign.center, | ||
onChanged: (newValue){ | ||
newTaskTitle = newValue; | ||
|
||
}, | ||
), | ||
FlatButton( | ||
onPressed: (){ | ||
Provider.of<TaskData>(context, listen: false).addTask(newTaskTitle); | ||
Navigator.pop(context); | ||
|
||
}, | ||
color: Colors.lightBlueAccent, | ||
child: const Text('Add'), | ||
|
||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
class Task{ | ||
final String? name ; | ||
bool? isDone; | ||
Task({this.name, this.isDone= false}); | ||
|
||
void toggleDone(){ | ||
isDone = !isDone!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'dart:collection'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:todolistapp_updates/models/task.dart'; | ||
|
||
class TaskData extends ChangeNotifier{ | ||
final List<Task> _tasks = [ | ||
Task(name: 'Buy milk'), | ||
Task(name: 'Buy eggs'), | ||
Task(name: 'Buy breads'), | ||
]; | ||
|
||
// List<Task> get tasks { | ||
// return _tasks; | ||
// } | ||
|
||
UnmodifiableListView <Task> get tasks{ | ||
return UnmodifiableListView(_tasks); | ||
} | ||
int get taskCount{ | ||
return _tasks.length; | ||
} | ||
void addTask(String newTaskTitle){ | ||
final task = Task(name: newTaskTitle); | ||
_tasks.add(task); | ||
notifyListeners(); | ||
} | ||
|
||
void updateTask(Task task){ | ||
task.toggleDone(); | ||
notifyListeners(); | ||
} | ||
void deleteTask(Task task){ | ||
_tasks.remove(task); | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:todolistapp_updates/widgets/TasksTile.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:todolistapp_updates/models/task_data.dart'; | ||
|
||
class TasksList extends StatelessWidget { | ||
const TasksList({Key? key}) : super(key: key); | ||
@override | ||
Widget build(BuildContext context) { | ||
return Consumer<TaskData>( | ||
builder: (context, taskData, child) { | ||
return ListView.builder( | ||
itemBuilder: (context, index) { | ||
final task = taskData.tasks[index]; | ||
return TaskTile( | ||
taskTitle: Provider.of<TaskData>(context).tasks[index].name, | ||
isChecked: Provider.of<TaskData>(context).tasks[index].isDone, | ||
checkboxCallback: (bool checkboxState) { | ||
taskData.updateTask(task); | ||
}, | ||
longPressCallback: (){ | ||
taskData.deleteTask(task); | ||
}, | ||
); | ||
}, | ||
itemCount:taskData.taskCount, | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class TaskTile extends StatelessWidget { | ||
|
||
final bool? isChecked ; | ||
final String? taskTitle; | ||
final Function checkboxCallback; | ||
final Function longPressCallback; | ||
const TaskTile({Key? key, this.isChecked , this.taskTitle, required this.checkboxCallback, required this.longPressCallback}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ListTile( | ||
onLongPress: (){ | ||
longPressCallback(); | ||
} , | ||
title: Text( | ||
taskTitle!, | ||
style: TextStyle( | ||
decoration: isChecked! ? TextDecoration.lineThrough : null, | ||
fontSize: 20, | ||
), | ||
), | ||
trailing: Checkbox( | ||
activeColor: Colors.lightBlueAccent, | ||
value: isChecked, | ||
onChanged: (newValue){ | ||
checkboxCallback(newValue); | ||
}, | ||
), | ||
); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters