showCreateZoneDialog function
Show create zone dialog.
Implementation
Future<void> showCreateZoneDialog(BuildContext context, NmZoneController controller) async {
final l10n = NmTelecom.l10n(context);
final id = TextEditingController();
final name = TextEditingController();
final region = TextEditingController();
String? error;
await showDialog<void>(
context: context,
builder: (dialogContext) => StatefulBuilder(
builder: (context, setState) => AlertDialog(
title: Row(children: [const NmIcon(NmFugue.applicationBadgePlus), const SizedBox(width: 8), Text(l10n.zoneNewDialogTitle)]),
content: SizedBox(
width: 420,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
_field(id, l10n.zoneIdFieldLabel, required: true),
const SizedBox(height: 10),
_field(name, l10n.zoneFieldName, required: true),
const SizedBox(height: 10),
_field(region, l10n.zoneFieldRegionOptional),
if (error != null) ...[
const SizedBox(height: 10),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const NmIcon(NmFugue.exclamation),
const SizedBox(width: 8),
Expanded(
child: Text(
error!,
style: context.nm.text.body.copyWith(color: context.nm.colors.dangerText, fontWeight: FontWeight.w600),
),
),
],
),
],
],
),
),
actions: [
TextButton(onPressed: () => Navigator.pop(dialogContext), child: Text(NmL10n.of(context).actionCancel)),
FilledButton(
onPressed: () {
final idValue = id.text.trim();
final nameValue = name.text.trim();
if (idValue.isEmpty || nameValue.isEmpty) {
setState(() => error = l10n.zoneValIdNameRequired);
return;
}
try {
controller.createZone(idValue, nameValue, region.text.trim().isEmpty ? null : region.text.trim(), l10n);
Navigator.pop(dialogContext);
} on NmZoneRepositoryException catch (e) {
setState(() => error = e.message);
}
},
child: Text(l10n.zoneCreateButton),
),
],
),
),
);
id.dispose();
name.dispose();
region.dispose();
}