diff options
Diffstat (limited to 'lib/widgets')
| -rw-r--r-- | lib/widgets/agenda_week.dart | 56 | ||||
| -rw-r--r-- | lib/widgets/agenda_week_item.dart | 63 |
2 files changed, 86 insertions, 33 deletions
diff --git a/lib/widgets/agenda_week.dart b/lib/widgets/agenda_week.dart index 4a654ce..754a46b 100644 --- a/lib/widgets/agenda_week.dart +++ b/lib/widgets/agenda_week.dart @@ -10,11 +10,12 @@ class AgendaWeek extends StatefulWidget { final int weekNr; final DateTime mondayOfWeek; final bool isCurrentWeek; + Function? updateFunc; @override _AgendaWeekState createState() => _AgendaWeekState(); - const AgendaWeek({ + AgendaWeek({ Key? key, required this.weekNr, required this.mondayOfWeek, @@ -25,31 +26,40 @@ class AgendaWeek extends StatefulWidget { class _AgendaWeekState extends State<AgendaWeek> { List<Widget> weekItems = []; - @override - void initState() { - super.initState(); + void updateItems() { + setState(() { + shiftProvider + .getShiftsForWeek(this.widget.mondayOfWeek) + .then((value) => setState(() { + weekItems = [ + AgendaWeekTitle( + weekNr: this.widget.weekNr, + mondayOfWeek: this.widget.mondayOfWeek, + isCurrentWeek: this.widget.isCurrentWeek), + Padding( + padding: const EdgeInsets.all(10), + ) + ]; - shiftProvider - .getShiftsForWeek(this.widget.mondayOfWeek) - .then((value) => setState(() { - weekItems = [ - AgendaWeekTitle( - weekNr: this.widget.weekNr, - mondayOfWeek: this.widget.mondayOfWeek, - isCurrentWeek: this.widget.isCurrentWeek), - Padding( - padding: const EdgeInsets.all(10), - ) - ]; + for (var item in value) { + weekItems.add(new AgendaWeekItem( + shift: item, + updateParent: updateItems, + )); + } - for (var item in value) { - weekItems.add(new AgendaWeekItem(shift: item)); - } + weekItems.add(Padding( + padding: const EdgeInsets.all(50), + )); + })); + }); + } - weekItems.add(Padding( - padding: const EdgeInsets.all(50), - )); - })); + @override + void initState() { + super.initState(); + updateItems(); + widget.updateFunc = updateItems; } @override diff --git a/lib/widgets/agenda_week_item.dart b/lib/widgets/agenda_week_item.dart index f3145dd..779b42d 100644 --- a/lib/widgets/agenda_week_item.dart +++ b/lib/widgets/agenda_week_item.dart @@ -10,9 +10,12 @@ import '../style/style.dart'; class AgendaWeekItem extends StatefulWidget { final Shift shift; + final Function updateParent; + const AgendaWeekItem({ Key? key, required this.shift, + required this.updateParent, }) : super(key: key); @override @@ -186,7 +189,7 @@ class _ExerciseEntryState extends State<AgendaWeekItem> { endTime.hour, endTime.minute); - shiftProvider.updateShift(widget.shift); + await shiftProvider.updateShift(widget.shift); } Widget createCompleteOldShiftButton() { @@ -209,6 +212,41 @@ class _ExerciseEntryState extends State<AgendaWeekItem> { return Padding(padding: const EdgeInsets.all(0)); } + void showDeleteShiftModal() { + // set up the buttons + Widget cancelButton = FlatButton( + child: Text("Terug"), + onPressed: () { + Navigator.pop(context); + }, + ); + Widget continueButton = FlatButton( + child: Text("Verwijder"), + onPressed: () async { + await shiftProvider.deleteShift(widget.shift); + Navigator.pop(context); + widget.updateParent(); + }, + ); + // set up the AlertDialog + AlertDialog alert = AlertDialog( + title: Text("Verwijderen"), + content: Text("Werktijd verwijderen uit schema?"), + actions: [ + cancelButton, + continueButton, + ], + ); + + // show the dialog + showDialog( + context: context, + builder: (BuildContext context) { + return alert; + }, + ); + } + @override Widget build(BuildContext context) { Widget startShiftWidget = createShiftModifyButton(); @@ -240,15 +278,20 @@ class _ExerciseEntryState extends State<AgendaWeekItem> { padding: EdgeInsets.only(right: 5), child: Row( children: [ - Container( - decoration: BoxDecoration( - color: widget.shift.getStatusColor(), - borderRadius: BorderRadius.only( - topLeft: Radius.circular(8), - bottomLeft: Radius.circular(8))), - height: 48.0, - width: 32.0, - child: widget.shift.getStatusIcon(), + GestureDetector( + onLongPress: () { + showDeleteShiftModal(); + }, + child: Container( + decoration: BoxDecoration( + color: widget.shift.getStatusColor(), + borderRadius: BorderRadius.only( + topLeft: Radius.circular(8), + bottomLeft: Radius.circular(8))), + height: 48.0, + width: 32.0, + child: widget.shift.getStatusIcon(), + ), ), Container( padding: const EdgeInsets.only(left: 10), |
