Todo delete + Debug Logging to User
This commit is contained in:
480
lib/Todos.dart
480
lib/Todos.dart
@@ -1,4 +1,5 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
@@ -7,6 +8,7 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
||||
import 'package:tasktracker/NewJournal.dart';
|
||||
import 'package:tasktracker/NewTodo.dart';
|
||||
import 'package:tasktracker/main.dart';
|
||||
import 'Data.dart';
|
||||
import 'User.dart' as User;
|
||||
import 'Dialogs.dart';
|
||||
|
||||
@@ -19,7 +21,6 @@ class TodosPage extends StatefulWidget {
|
||||
|
||||
class _TodosPageState extends State<TodosPage> {
|
||||
bool selecting = false;
|
||||
List<int> selectedIndexes = [];
|
||||
int expandedIndex = -1;
|
||||
var refreshStream;
|
||||
|
||||
@@ -42,8 +43,27 @@ class _TodosPageState extends State<TodosPage> {
|
||||
refreshStream?.close();
|
||||
}
|
||||
|
||||
Map<String, List<Todo>> projects = <String, List<Todo>>{};
|
||||
List<Todo> simpleTodos = [];
|
||||
List<String> expandedProjects = [];
|
||||
bool expandedSimpleTodos = false;
|
||||
List<String> selectedProjects = [];
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
projects = <String, List<Todo>>{};
|
||||
simpleTodos = [];
|
||||
for (var todo in User.todos) {
|
||||
if (todo.task!.relatedProject != null) {
|
||||
String projectName = todo.task!.relatedProject!.name;
|
||||
if (projects.containsKey(projectName)) {
|
||||
projects[projectName]!.add(todo);
|
||||
} else {
|
||||
projects.putIfAbsent(projectName, () => [todo]);
|
||||
}
|
||||
}else{
|
||||
simpleTodos.add(todo);
|
||||
}
|
||||
}
|
||||
return Scaffold(
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
@@ -68,13 +88,11 @@ class _TodosPageState extends State<TodosPage> {
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
if (selecting && selectedIndexes.length > 0)
|
||||
if (selecting && selectedProjects.length > 0)
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
onTap: () {
|
||||
selecting = false;
|
||||
for (int element in selectedIndexes) {
|
||||
await User.UserOperations.deleteJournal(User.todos[element].id);
|
||||
}
|
||||
deleteTodos();
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(margin: EdgeInsets.all(8), child: Icon(Icons.delete))),
|
||||
@@ -100,179 +118,289 @@ class _TodosPageState extends State<TodosPage> {
|
||||
),
|
||||
),
|
||||
drawer: navDrawer(context, 9),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: ScrollablePositionedList.builder(
|
||||
itemCount: User.todos.length,
|
||||
itemBuilder: (context, index) {
|
||||
int maxCharCount = 100;
|
||||
bool containsStepData = User.todos[index].metadata.contains('[') && User.todos[index].metadata.contains(']');
|
||||
return Container(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (selecting) {
|
||||
if (selectedIndexes.contains(index)) {
|
||||
selectedIndexes.remove(index);
|
||||
} else {
|
||||
selectedIndexes.add(index);
|
||||
}
|
||||
setState(() {});
|
||||
} else {
|
||||
if (expandedIndex == index) {
|
||||
expandedIndex = -1;
|
||||
//_controller..reverse(from: 0.5);
|
||||
} else {
|
||||
expandedIndex = index;
|
||||
// _controller..forward(from: 0);
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
selecting = !selecting;
|
||||
if (!selectedIndexes.contains(index)) {
|
||||
selectedIndexes.add(index);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
if (selecting)
|
||||
Checkbox(
|
||||
value: selectedIndexes.contains(index),
|
||||
onChanged: (newVal) {
|
||||
if (selectedIndexes.contains(index)) {
|
||||
selectedIndexes.remove(index);
|
||||
} else {
|
||||
selectedIndexes.add(index);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
Card(
|
||||
body: SingleChildScrollView(
|
||||
// margin: EdgeInsets.fromLTRB(2, 10, 0, 10),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.all(8),
|
||||
padding: EdgeInsets.symmetric(vertical: 10),
|
||||
decoration: BoxDecoration(color: Colors.black26, borderRadius: BorderRadius.circular(10)),
|
||||
child: (projects.length <=0) ?Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('No Todos Related to Projects'),
|
||||
],
|
||||
) :ScrollablePositionedList.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: projects.length,
|
||||
itemBuilder: (context, i) {
|
||||
String thisProject= projects.keys.toList()[i];
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 0,vertical: 8),
|
||||
child: Column(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: (){
|
||||
if(expandedProjects.contains(thisProject)){
|
||||
expandedProjects.remove(thisProject);
|
||||
}else{
|
||||
expandedProjects.add(thisProject);
|
||||
|
||||
// color: color,
|
||||
elevation: 30,
|
||||
shadowColor: colorFromHex(User.todos[index].task!.cat!.color),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
//Open Respective Category
|
||||
if (selecting) {
|
||||
//OnItemSelected(activity);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
onLongPress: () {
|
||||
print('gonna delete');
|
||||
selecting = !selecting;
|
||||
// selectedActivities = [activity];
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||
Text(User.todos[index].task!.name, style: TextStyle(fontSize: 17)),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [
|
||||
Icon(
|
||||
Icons.arrow_forward_outlined,
|
||||
size: 20,
|
||||
),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 3,
|
||||
child: Text(
|
||||
(containsStepData)
|
||||
? User.todos[index].metadata.substring(User.todos[index].metadata!.indexOf(']') + 1)
|
||||
: (User.todos[index].metadata ?? ''),
|
||||
),
|
||||
),
|
||||
]),
|
||||
// Icon(Icons.analytics, color: color, size: 20,),
|
||||
]),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.blue),
|
||||
child: Text(DateFormat('yyyy-MM-dd').format(User.todos[index].dueDate))),
|
||||
SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
(User.todos[index].task!.relatedProject != null)
|
||||
? Row(
|
||||
children: [
|
||||
if (containsStepData)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
decoration:
|
||||
BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black26),
|
||||
child: Text(User.todos[index].metadata!
|
||||
.substring(1, User.todos[index].metadata!.indexOf(']')) ??
|
||||
'n/a')),
|
||||
SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
decoration:
|
||||
BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black26),
|
||||
child: Text(User.todos[index].task!.relatedProject!.name ?? 'n/a')),
|
||||
],
|
||||
)
|
||||
: Container(),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: (User.todos[index].task!.cat!.productive) ? Colors.green : Colors.red),
|
||||
child: Text(User.todos[index].task!.cat?.name ?? 'n/a')),
|
||||
],
|
||||
)
|
||||
// Icon(Icons.circle,
|
||||
// color: (productive)
|
||||
// ? Colors.green
|
||||
// : Colors.red)
|
||||
])
|
||||
],
|
||||
)))),
|
||||
Container(
|
||||
margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
|
||||
height: 2,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(flex: 100, child: Container(color: colorFromHex(User.todos[index].task!.cat!.color))),
|
||||
Expanded(flex: 0, child: Container())
|
||||
],
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (selecting)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
// Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewJournal(date: User.todos[index].day, title: User.todos[index].title, text: User.todos[index].description,))).then((val) {
|
||||
// setState(() {});
|
||||
// });
|
||||
selecting = false;
|
||||
setState(() {});
|
||||
}
|
||||
setState(() {
|
||||
|
||||
});
|
||||
},
|
||||
child: Container(margin: EdgeInsets.all(8), child: FaIcon(FontAwesomeIcons.edit)))
|
||||
],
|
||||
),
|
||||
));
|
||||
}),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon((!expandedProjects.contains(thisProject)) ? Icons.keyboard_arrow_right_outlined : Icons.keyboard_arrow_down_outlined),
|
||||
Text('${projects.keys.toList()[i]} (${projects.values.toList()[i].length})',style: TextStyle(fontSize: 18)),
|
||||
],
|
||||
),
|
||||
Container(),
|
||||
],
|
||||
),
|
||||
),
|
||||
if(expandedProjects.contains(thisProject))Container(
|
||||
padding: EdgeInsets.fromLTRB(8, 0, 8, 0),
|
||||
child: ScrollablePositionedList.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: projects.values.toList()[i].length,
|
||||
itemBuilder: (context, index) {
|
||||
int maxCharCount = 100;
|
||||
Todo todo = projects.values.toList()[i][index];
|
||||
|
||||
print('$i : $index');
|
||||
return todoCard(todo);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.all(8),
|
||||
padding: EdgeInsets.symmetric(vertical: 10),
|
||||
decoration: BoxDecoration(color: Colors.black26, borderRadius: BorderRadius.circular(15)),
|
||||
child: Column(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: (){expandedSimpleTodos=!expandedSimpleTodos;setState(() {
|
||||
|
||||
});},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon((!expandedSimpleTodos) ? Icons.keyboard_arrow_right_outlined : Icons.keyboard_arrow_down_outlined),
|
||||
Text('Typical Todos (${simpleTodos.length})',style: TextStyle(fontSize: 18)),
|
||||
],
|
||||
),
|
||||
Container(),
|
||||
],
|
||||
),
|
||||
),
|
||||
if(expandedSimpleTodos)Container(
|
||||
padding: EdgeInsets.fromLTRB(8, 0, 8, 0),
|
||||
child: ScrollablePositionedList.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: simpleTodos.length,
|
||||
itemBuilder: (context, index) {
|
||||
int maxCharCount = 100;
|
||||
Todo todo = simpleTodos[index];
|
||||
return todoCard(todo);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget todoCard(Todo todo){
|
||||
|
||||
bool containsStepData = todo.metadata.contains('[') && todo.metadata.contains(']');
|
||||
|
||||
return Container(
|
||||
child: InkWell(
|
||||
child: Row(
|
||||
children: [
|
||||
if (selecting)
|
||||
Checkbox(
|
||||
value: selectedProjects.contains(todo.id),
|
||||
onChanged: (newVal) {
|
||||
if (selectedProjects.contains(todo.id)) {
|
||||
selectedProjects.remove(todo.id);
|
||||
} else {
|
||||
selectedProjects.add(todo.id);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
Card(
|
||||
|
||||
// color: color,
|
||||
elevation: 30,
|
||||
shadowColor: colorFromHex(todo.task!.cat!.color),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
//Open Respective Category
|
||||
if (selecting) {
|
||||
if (selectedProjects.contains(todo.id)) {
|
||||
selectedProjects.remove(todo.id);
|
||||
} else {
|
||||
selectedProjects.add(todo.id);
|
||||
}
|
||||
setState(() {});
|
||||
} else {
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
print('gonna delete');
|
||||
selecting = !selecting;
|
||||
selectedProjects=[];
|
||||
// selectedActivities = [activity];
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||
Text(todo.task!.name, style: TextStyle(fontSize: 17)),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [
|
||||
Icon(
|
||||
Icons.arrow_forward_outlined,
|
||||
size: 20,
|
||||
),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 3,
|
||||
child: Text(
|
||||
(containsStepData)
|
||||
? todo.metadata.substring(todo.metadata!.indexOf(']') + 1)
|
||||
: (todo.metadata ?? ''),
|
||||
),
|
||||
),
|
||||
]),
|
||||
// Icon(Icons.analytics, color: color, size: 20,),
|
||||
]),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.blue),
|
||||
child: Text(DateFormat('yyyy-MM-dd').format(todo.dueDate))),
|
||||
SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
(todo.task!.relatedProject != null)
|
||||
? Row(
|
||||
children: [
|
||||
if (containsStepData)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
decoration:
|
||||
BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black26),
|
||||
child: Text(todo.metadata!
|
||||
.substring(1, todo.metadata!.indexOf(']')) ??
|
||||
'n/a')),
|
||||
SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black26),
|
||||
child: Text(todo.task!.relatedProject!.name ?? 'n/a')),
|
||||
],
|
||||
)
|
||||
: Container(),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: (todo.task!.cat!.productive) ? Colors.green : Colors.red),
|
||||
child: Text(todo.task!.cat?.name ?? 'n/a')),
|
||||
],
|
||||
)
|
||||
// Icon(Icons.circle,
|
||||
// color: (productive)
|
||||
// ? Colors.green
|
||||
// : Colors.red)
|
||||
])
|
||||
],
|
||||
)))),
|
||||
Container(
|
||||
margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
|
||||
height: 2,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(flex: 100, child: Container(color: colorFromHex(todo.task!.cat!.color))),
|
||||
Expanded(flex: 0, child: Container())
|
||||
],
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (selecting)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
// Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewJournal(date: todo.day, title: todo.title, text: todo.description,))).then((val) {
|
||||
// setState(() {});
|
||||
// });
|
||||
selecting = false;
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(margin: EdgeInsets.all(8), child: FaIcon(FontAwesomeIcons.edit)))
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
void deleteTodos() async{
|
||||
if(selectedProjects.length > 0){
|
||||
User.todos.forEach((list) {
|
||||
selectedProjects.forEach((selected) {
|
||||
if(list.id == selected){
|
||||
User.UserOperations.deleteTodo(selected,bulk: true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
await User.UserOperations.executeQueries();
|
||||
|
||||
}else{
|
||||
Dialogs.showAlertDialog(context, 'Non-Selected', 'Select some tasks to delete, This message should not be shown btw');
|
||||
}
|
||||
}
|
||||
|
||||
// List<Widget> todos() {
|
||||
// List<Widget> _todos = [];
|
||||
// for (int i = 0; i < projects.length; i++) {
|
||||
// _todos.add(;
|
||||
// }
|
||||
// return _todos;
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user