Offline Support
This commit is contained in:
@@ -258,30 +258,48 @@ class _OfficesScreenState extends ConsumerState<OfficesScreen> {
|
||||
return;
|
||||
}
|
||||
setState(() => saving = true);
|
||||
final controller = ref.read(
|
||||
officesControllerProvider,
|
||||
);
|
||||
if (office == null) {
|
||||
await controller.createOffice(
|
||||
name: name,
|
||||
serviceId: selectedServiceId,
|
||||
);
|
||||
} else {
|
||||
await controller.updateOffice(
|
||||
id: office.id,
|
||||
name: name,
|
||||
serviceId: selectedServiceId,
|
||||
);
|
||||
}
|
||||
ref.invalidate(officesProvider);
|
||||
if (context.mounted) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
showSuccessSnackBar(
|
||||
context,
|
||||
office == null
|
||||
? 'Office "$name" has been created successfully.'
|
||||
: 'Office "$name" has been updated successfully.',
|
||||
try {
|
||||
final controller = ref.read(
|
||||
officesControllerProvider,
|
||||
);
|
||||
if (office == null) {
|
||||
await controller.createOffice(
|
||||
name: name,
|
||||
serviceId: selectedServiceId,
|
||||
);
|
||||
} else {
|
||||
await controller.updateOffice(
|
||||
id: office.id,
|
||||
name: name,
|
||||
serviceId: selectedServiceId,
|
||||
);
|
||||
}
|
||||
ref.invalidate(officesProvider);
|
||||
if (context.mounted) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
showSuccessSnackBar(
|
||||
context,
|
||||
office == null
|
||||
? 'Office "$name" has been created successfully.'
|
||||
: 'Office "$name" has been updated successfully.',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!dialogContext.mounted) return;
|
||||
if (isOfflineSaveError(e)) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
showSuccessSnackBarGlobal(
|
||||
office == null
|
||||
? 'Office "$name" saved offline — will sync when connected.'
|
||||
: 'Office "$name" update saved offline — will sync when connected.',
|
||||
);
|
||||
} else {
|
||||
showErrorSnackBar(context, 'Failed to save: $e');
|
||||
}
|
||||
} finally {
|
||||
if (dialogContext.mounted) {
|
||||
setState(() => saving = false);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: saving
|
||||
|
||||
Reference in New Issue
Block a user