Projects Details (error)

This commit is contained in:
Sewmina
2022-03-27 21:16:29 +05:30
parent f64ac7efbd
commit 2f280f1795
11 changed files with 429 additions and 55 deletions

View File

@@ -3,16 +3,19 @@ import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:intl/intl.dart';
import 'package:tasktracker/NewCategory.dart';
import 'package:tasktracker/NewProject.dart';
import 'Data.dart';
import 'User.dart' as User;
DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat durationFormat = DateFormat("HH:mm:ss");
class NewTask extends StatefulWidget {
const NewTask({Key? key}) : super(key: key);
NewTask({Key? key, this.t_cat, this.t_name, this.t_relProj}) : super(key: key);
late String? t_name;
late String? t_cat;
late String? t_relProj;
@override
_NewTaskState createState() => _NewTaskState();
_NewTaskState createState() => _NewTaskState(t_cat: t_cat, t_name: t_name, t_relProj: t_relProj);
}
List<String> getCategoryNames(){
@@ -39,6 +42,19 @@ List<String> getProjectNames(){
String selectedCat = User.categories[0].name;
String selectedProj = "None";
class _NewTaskState extends State<NewTask> {
bool editing = false;
String? oldName;
_NewTaskState({String? t_name, String? t_cat, String? t_relProj}){
if(t_name !=null && t_cat != null){
editing = true;
oldName = t_name;
}
nameController.text = t_name ?? '';
selectedCat = t_cat ?? User.categories[0].name;
selectedProj = t_relProj ?? 'None';
}
TextEditingController nameController = TextEditingController();
bool productive = true;
@@ -46,7 +62,7 @@ class _NewTaskState extends State<NewTask> {
Widget build(BuildContext context) {
List<String> cats = getCategoryNames();
return Scaffold(
appBar: AppBar(title: Text('New Task Type')),
appBar: AppBar(title: Text('${(editing) ? 'Edit ' : 'New '} Task Type')),
body: Container(
height: MediaQuery.of(context).size.height,
child: Column(
@@ -99,7 +115,7 @@ class _NewTaskState extends State<NewTask> {
child: Text(value),
);
}).toList(),
onChanged: (String? _value) {
onChanged:(selectedProj == 'None') ? (String? _value) {
if(_value != null) {
if (_value.contains("+Add New Category")) {
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>NewCategory()));
@@ -110,7 +126,7 @@ class _NewTaskState extends State<NewTask> {
setState(() {
});
})),
} : null)),
Padding(
padding: const EdgeInsets.fromLTRB(0, 20, 0, 10),
child: Text('Related Project'),
@@ -138,7 +154,7 @@ class _NewTaskState extends State<NewTask> {
child: Text(value),
);
}).toList(),
onChanged: (String? _value) {
onChanged: (String? _value) async{
if(_value != null) {
if (_value.contains("+Add New Project")) {
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>NewProject()));
@@ -146,6 +162,13 @@ class _NewTaskState extends State<NewTask> {
selectedProj = _value!;
if(_value.contains("None")){
}else{
Project? relProj = await User.getProjectFromId(selectedProj);
if(relProj==null){
}else{
selectedCat = relProj.cat!.name;
}
}
}
}
@@ -195,10 +218,14 @@ class _NewTaskState extends State<NewTask> {
),
onPressed: () {
setState(() {
add_action();
if(editing){
edit_action();
}else {
add_action();
}
});
},
child: Text('Add Task Type',
child: Text((editing) ? 'Apply' : 'Add Task Type',
style: TextStyle(fontSize: 20))))),
],
))
@@ -217,6 +244,19 @@ class _NewTaskState extends State<NewTask> {
return route.isFirst;
});
}
void edit_action() async{
String catName = nameController.value.text;
print('editing Task Type $oldName => : $catName, $selectedCat');
if(catName.length< 2){
showAlertDialog(context, 'Category needs a name', 'Please enter a name for this category');
return;
}
await User.UserOperations.editTaskType(oldName! ,catName,selectedCat,relatedProject: (selectedProj == 'None') ? '' : selectedProj);
Navigator.of(context).popUntil((route){
return route.isFirst;
});
}
}
String _printDuration(Duration duration) {