Related Project added to TaskType
This commit is contained in:
136
lib/Tasks.dart
136
lib/Tasks.dart
@@ -10,31 +10,33 @@ class Tasks extends StatefulWidget {
|
||||
@override
|
||||
_TasksState createState() => _TasksState();
|
||||
}
|
||||
|
||||
class _TasksState extends State<Tasks> {
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
// UpdateList();
|
||||
// init(context);
|
||||
// UpdateList();
|
||||
// init(context);
|
||||
}
|
||||
|
||||
var refreshSub;
|
||||
void init(BuildContext context) async{
|
||||
void init(BuildContext context) async {
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
refreshSub = User.refreshStream.stream.listen((value) {
|
||||
print("Streaming refresh : $value");
|
||||
if(value){
|
||||
if (value) {
|
||||
// dialogs.waiting(context, "Syncing");
|
||||
print("Opening progress dialog");
|
||||
}else{
|
||||
} else {
|
||||
// dialogs.hide(context);
|
||||
print("Closing progress dialog");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override void dispose() {
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
super.dispose();
|
||||
refreshSub?.cancel();
|
||||
@@ -43,34 +45,41 @@ class _TasksState extends State<Tasks> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (context) => NewTask()))
|
||||
.then((value) => UpdateList());
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewTask())).then((value) => UpdateList());
|
||||
},
|
||||
label: Text("New Task Type"),
|
||||
icon: Icon(Icons.add)),
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(children: [
|
||||
Icon(Icons.task, color: Theme.of(context).primaryColor),
|
||||
SizedBox(width: 10),
|
||||
Text('Task Types')
|
||||
]),
|
||||
(selecting)?Row(children: [
|
||||
InkWell(onTap: (){
|
||||
DeleteSelectedTasks();
|
||||
}, child: Icon(Icons.delete,size: 30,)),
|
||||
SizedBox(width: 20,),
|
||||
InkWell(onTap: (){setState(() {
|
||||
selecting=false;
|
||||
});}, child: Icon(Icons.close,size: 30),)
|
||||
]) : Container(),
|
||||
Row(children: [Icon(Icons.task, color: Theme.of(context).primaryColor), SizedBox(width: 10), Text('Task Types')]),
|
||||
(selecting)
|
||||
? Row(children: [
|
||||
InkWell(
|
||||
onTap: () {
|
||||
DeleteSelectedTasks();
|
||||
},
|
||||
child: Icon(
|
||||
Icons.delete,
|
||||
size: 30,
|
||||
)),
|
||||
SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selecting = false;
|
||||
});
|
||||
},
|
||||
child: Icon(Icons.close, size: 30),
|
||||
)
|
||||
])
|
||||
: Container(),
|
||||
],
|
||||
)),
|
||||
drawer: navDrawer(context, 3),
|
||||
@@ -83,13 +92,12 @@ class _TasksState extends State<Tasks> {
|
||||
}
|
||||
|
||||
void UpdateList() async {
|
||||
|
||||
// try{progressDialog.show(max:100, msg: 'Loading Task Types...');}catch(e){}
|
||||
// try{progressDialog.show(max:100, msg: 'Loading Task Types...');}catch(e){}
|
||||
await User.refreshUserData();
|
||||
// hideProgressDialog();
|
||||
if(mounted)setState(() {});
|
||||
// hideProgressDialog();
|
||||
if (mounted) setState(() {});
|
||||
|
||||
// try{progressDialog.update(value: 100);}catch(e){}
|
||||
// try{progressDialog.update(value: 100);}catch(e){}
|
||||
}
|
||||
|
||||
List<Widget> PrintTasks() {
|
||||
@@ -102,7 +110,8 @@ class _TasksState extends State<Tasks> {
|
||||
} else {
|
||||
Color color = HexColor.fromHex(element.cat?.color ?? '#000000');
|
||||
bool productive = element.cat?.productive ?? true;
|
||||
Widget task = TaskCard(context, name, productive, color, element.cat?.name ?? 'n/a');
|
||||
Widget task = TaskCard(
|
||||
context, name, productive, color, element.cat?.name ?? 'n/a', (element.relatedProject != null) ? element.relatedProject!.getName() : '');
|
||||
_tasks.add(task);
|
||||
}
|
||||
});
|
||||
@@ -111,8 +120,7 @@ class _TasksState extends State<Tasks> {
|
||||
}
|
||||
|
||||
bool selecting = false;
|
||||
Widget TaskCard(
|
||||
BuildContext context, String name, bool productive, Color color, String catName) {
|
||||
Widget TaskCard(BuildContext context, String name, bool productive, Color color, String catName, String relatedProjects) {
|
||||
return Row(children: [
|
||||
// Container(),
|
||||
(selecting)
|
||||
@@ -129,57 +137,58 @@ class _TasksState extends State<Tasks> {
|
||||
Card(
|
||||
|
||||
// color: color,
|
||||
elevation:20,
|
||||
elevation: 20,
|
||||
shadowColor: color,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
//Open Respective Category
|
||||
if(selecting){
|
||||
if (selecting) {
|
||||
OnItemSelected(name);
|
||||
}
|
||||
setState(() {
|
||||
|
||||
});
|
||||
setState(() {});
|
||||
},
|
||||
onLongPress: () {
|
||||
print('gonna delete');
|
||||
selecting = !selecting;
|
||||
selectedTasks = [name];
|
||||
setState(() {});
|
||||
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Text(
|
||||
name,
|
||||
),
|
||||
// Icon(Icons.analytics, color: color, size: 20,),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(name,
|
||||
),
|
||||
// Icon(Icons.analytics, color: color, size: 20,),
|
||||
(relatedProjects.isNotEmpty)
|
||||
? Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration:
|
||||
BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black26),
|
||||
child: Text(relatedProjects))
|
||||
: Container(),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: (productive) ? Colors.green : Colors.red
|
||||
),
|
||||
child:Text(catName)
|
||||
)
|
||||
]),
|
||||
decoration:
|
||||
BoxDecoration(borderRadius: BorderRadius.circular(10), color: (productive) ? Colors.green : Colors.red),
|
||||
child: Text(catName)),
|
||||
],
|
||||
)
|
||||
]),
|
||||
],
|
||||
)))),
|
||||
Container(
|
||||
margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
|
||||
height: 2,
|
||||
color: color)
|
||||
Container(margin: EdgeInsets.fromLTRB(15, 0, 15, 10), height: 2, color: color)
|
||||
]),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
void OnItemSelected(String name){
|
||||
void OnItemSelected(String name) {
|
||||
if (!selectedTasks.contains(name)) {
|
||||
selectedTasks.add(name);
|
||||
} else {
|
||||
@@ -187,20 +196,17 @@ class _TasksState extends State<Tasks> {
|
||||
}
|
||||
}
|
||||
|
||||
void DeleteSelectedTasks() async{
|
||||
void DeleteSelectedTasks() async {
|
||||
selectedTasks.forEach((element) async {
|
||||
await User.UserOperations.deleteTask(element, bulk:true);
|
||||
await User.UserOperations.deleteTask(element, bulk: true);
|
||||
});
|
||||
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
await User.UserOperations.executeQueries();
|
||||
selectedTasks=[];
|
||||
selecting=false;
|
||||
setState(() {
|
||||
});
|
||||
|
||||
selectedTasks = [];
|
||||
selecting = false;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<String> selectedTasks = [];
|
||||
|
||||
Reference in New Issue
Block a user