Basic Functions done
This commit is contained in:
@@ -12,17 +12,23 @@ class NewActivity extends StatefulWidget {
|
||||
_NewActivity createState() => _NewActivity();
|
||||
}
|
||||
|
||||
List<String> getActivitiesNames(){
|
||||
String selectedCat = User.taskTypes[0].name;
|
||||
|
||||
List<String> getActivities(){
|
||||
List<String> _cats = [];
|
||||
User.activities.forEach((element) {
|
||||
String name = element.taskType.name;
|
||||
_cats.add(name);
|
||||
print(User.taskTypes[0].name + " : " + selectedCat);
|
||||
User.taskTypes.forEach((element) {
|
||||
String name = element.name;
|
||||
if(_cats.contains(element.name)){
|
||||
|
||||
}else{
|
||||
_cats.add(name);}
|
||||
});
|
||||
return _cats;
|
||||
}
|
||||
|
||||
class _NewActivity extends State<NewActivity> {
|
||||
String value = 'CS:GO';
|
||||
|
||||
DateTime startTime = DateTime.now();
|
||||
DateTime endTime = DateTime.now().add(Duration(minutes: 30));
|
||||
@override
|
||||
@@ -57,24 +63,19 @@ class _NewActivity extends State<NewActivity> {
|
||||
iconSize: 30,
|
||||
elevation: 10,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
value: value,
|
||||
value: selectedCat,
|
||||
isExpanded: true,
|
||||
items: <String>[
|
||||
'Rocket League',
|
||||
'CS:GO',
|
||||
'HALO',
|
||||
'Unity',
|
||||
'Add new Task Type...'
|
||||
].map<DropdownMenuItem<String>>(
|
||||
(String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
);
|
||||
}).toList(),
|
||||
items: getActivities().map<DropdownMenuItem<String>>(
|
||||
(String value) {
|
||||
print(value);
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? _value) {
|
||||
setState(() {
|
||||
value = _value!;
|
||||
selectedCat = _value ?? 'n/a';
|
||||
});
|
||||
})),
|
||||
Container(
|
||||
@@ -101,7 +102,14 @@ class _NewActivity extends State<NewActivity> {
|
||||
// print('change $date');
|
||||
}, onConfirm: (date) {
|
||||
setState(() {
|
||||
startTime = date;
|
||||
if(endTime.compareTo(date) < 0){
|
||||
const snackBar = SnackBar(
|
||||
content: Text('You cannot start something after you ended it!'),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
}else {
|
||||
startTime = date;
|
||||
}
|
||||
});
|
||||
},
|
||||
currentTime: startTime,
|
||||
@@ -136,7 +144,14 @@ class _NewActivity extends State<NewActivity> {
|
||||
// print('change $date');
|
||||
}, onConfirm: (date) {
|
||||
setState(() {
|
||||
endTime = date;
|
||||
if(startTime.compareTo(date) > 0){
|
||||
const snackBar = SnackBar(
|
||||
content: Text('You cannot end something before you start it!'),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
}else {
|
||||
endTime = date;
|
||||
}
|
||||
});
|
||||
},
|
||||
currentTime: endTime,
|
||||
@@ -151,7 +166,10 @@ class _NewActivity extends State<NewActivity> {
|
||||
),
|
||||
Text('Duration : ' +
|
||||
_printDuration(
|
||||
endTime.difference(startTime))),
|
||||
endTime.difference(startTime)),
|
||||
style:TextStyle(
|
||||
fontSize: 20,
|
||||
)),
|
||||
Divider(
|
||||
height: 30,
|
||||
),
|
||||
@@ -192,7 +210,12 @@ class _NewActivity extends State<NewActivity> {
|
||||
shape: StadiumBorder()
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {});
|
||||
|
||||
add_action();
|
||||
setState(() {
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
child: Text('Add Entry',
|
||||
style: TextStyle(fontSize: 20))))),
|
||||
@@ -200,6 +223,20 @@ class _NewActivity extends State<NewActivity> {
|
||||
))
|
||||
])));
|
||||
}
|
||||
|
||||
void add_action() async{
|
||||
|
||||
print('adding Task Type : $selectedCat at $startTime - $endTime');
|
||||
bool failed=false;
|
||||
await User.UserOperations.addActivity(selectedCat,startTime.toString(), endTime.toString(), onOverlap: (overlapCount){
|
||||
showAlertDialog(context, 'Error adding activity', 'Cannot add activity between ${dateFormat.format(startTime)} - ${dateFormat.format(endTime)}, $overlapCount activities are already added within this time range');
|
||||
failed=true;
|
||||
|
||||
});
|
||||
|
||||
if(!failed)
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
String _printDuration(Duration duration) {
|
||||
@@ -208,3 +245,29 @@ String _printDuration(Duration duration) {
|
||||
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
|
||||
return "${twoDigits(duration.inHours)}:$twoDigitMinutes:$twoDigitSeconds";
|
||||
}
|
||||
|
||||
showAlertDialog(BuildContext context, String title, String message) {
|
||||
|
||||
// set up the button
|
||||
Widget okButton = TextButton(
|
||||
child: Text("OK"),
|
||||
onPressed: () { Navigator.of(context).pop(); },
|
||||
);
|
||||
|
||||
// set up the AlertDialog
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text(title),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
okButton,
|
||||
],
|
||||
);
|
||||
|
||||
// show the dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user