mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 05:03:44 +02:00
fix: add validation error handling for week template saving
This commit is contained in:
parent
ec47ed4696
commit
05af323aa5
1 changed files with 25 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
import "package:flutter/material.dart";
|
||||
import "package:flutter_availability/src/service/errors.dart";
|
||||
import "package:flutter_availability/src/ui/view_models/template_daydata_view_model.dart";
|
||||
import "package:flutter_availability/src/ui/view_models/week_template_view_models.dart";
|
||||
import "package:flutter_availability/src/ui/widgets/color_selection.dart";
|
||||
|
@ -99,17 +100,32 @@ class _WeekTemplateModificationScreenState
|
|||
}
|
||||
|
||||
Future<void> onSavePressed() async {
|
||||
if (!_viewModel.isValid) {
|
||||
// TODO(freek): show error message
|
||||
return;
|
||||
}
|
||||
var template = _viewModel.toTemplate();
|
||||
if (widget.template == null) {
|
||||
await service.createTemplate(template);
|
||||
} else {
|
||||
await service.updateTemplate(template);
|
||||
AvailabilityError? error;
|
||||
try {
|
||||
if (widget.template == null) {
|
||||
await service.createTemplate(template);
|
||||
} else {
|
||||
await service.updateTemplate(template);
|
||||
}
|
||||
widget.onExit();
|
||||
} on BreakEndBeforeStartException {
|
||||
error = AvailabilityError.breakEndBeforeStart;
|
||||
} on BreakSubmittedDurationTooLongException {
|
||||
error = AvailabilityError.breakSubmittedDurationTooLong;
|
||||
} on TemplateEndBeforeStartException {
|
||||
error = AvailabilityError.endBeforeStart;
|
||||
} on TemplateBreakBeforeStartException {
|
||||
error = AvailabilityError.templateBreakBeforeStart;
|
||||
} on TemplateBreakAfterEndException {
|
||||
error = AvailabilityError.templateBreakAfterEnd;
|
||||
}
|
||||
if (error != null && context.mounted) {
|
||||
await options.errorDisplayBuilder(
|
||||
context,
|
||||
error,
|
||||
);
|
||||
}
|
||||
widget.onExit();
|
||||
}
|
||||
|
||||
useEffect(() {
|
||||
|
|
Loading…
Reference in a new issue