Todo basics added
This commit is contained in:
278
lib/Todos.dart
Normal file
278
lib/Todos.dart
Normal file
@@ -0,0 +1,278 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
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 'User.dart' as User;
|
||||
import 'Dialogs.dart';
|
||||
|
||||
class TodosPage extends StatefulWidget {
|
||||
const TodosPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<TodosPage> createState() => _TodosPageState();
|
||||
}
|
||||
|
||||
class _TodosPageState extends State<TodosPage> {
|
||||
bool selecting = false;
|
||||
List<int> selectedIndexes = [];
|
||||
int expandedIndex = -1;
|
||||
var refreshStream;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
refreshStream = User.refreshStream.stream.listen((event) {
|
||||
if (!event) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
super.dispose();
|
||||
refreshStream?.close();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewTodo())).then((val) {
|
||||
setState(() {});
|
||||
});
|
||||
},
|
||||
label: Text("New To-Do"),
|
||||
icon: Icon(Icons.add)),
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
FaIcon(FontAwesomeIcons.calendarCheck),
|
||||
SizedBox(
|
||||
width: 15,
|
||||
),
|
||||
Text('To-Do')
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
if (selecting && selectedIndexes.length > 0)
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
selecting = false;
|
||||
for (int element in selectedIndexes) {
|
||||
await User.UserOperations.deleteJournal(User.todos[element].id);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(margin: EdgeInsets.all(8), child: Icon(Icons.delete))),
|
||||
if (selecting)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
selecting = false;
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(margin: EdgeInsets.all(8), child: Icon(Icons.cancel))),
|
||||
if (!selecting)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(8),
|
||||
child: Icon(Icons.refresh),
|
||||
))
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
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(
|
||||
|
||||
// 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(() {});
|
||||
},
|
||||
child: Container(margin: EdgeInsets.all(8), child: FaIcon(FontAwesomeIcons.edit)))
|
||||
],
|
||||
),
|
||||
));
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user