168 lines
5.3 KiB
Dart
168 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
typedef QuickProviderData = ({
|
|
String name,
|
|
String address,
|
|
String city,
|
|
String zipCode,
|
|
String province,
|
|
});
|
|
|
|
class QuickProviderDialog extends StatefulWidget {
|
|
const QuickProviderDialog({super.key});
|
|
|
|
static Future<QuickProviderData?> show(BuildContext context) {
|
|
return showDialog<QuickProviderData>(
|
|
context: context,
|
|
builder: (context) => const QuickProviderDialog(),
|
|
);
|
|
}
|
|
|
|
@override
|
|
State<QuickProviderDialog> createState() => _QuickProviderDialogState();
|
|
}
|
|
|
|
class _QuickProviderDialogState extends State<QuickProviderDialog> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
final _nameController = TextEditingController();
|
|
final _addressController = TextEditingController();
|
|
final _cityController = TextEditingController();
|
|
final _zipController = TextEditingController();
|
|
final _provinceController = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_nameController.dispose();
|
|
_addressController.dispose();
|
|
_cityController.dispose();
|
|
_zipController.dispose();
|
|
_provinceController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _submit() {
|
|
if (_formKey.currentState!.validate()) {
|
|
Navigator.of(context).pop<QuickProviderData>((
|
|
name: _nameController.text.trim(),
|
|
address: _addressController.text.trim(),
|
|
city: _cityController.text.trim(),
|
|
zipCode: _zipController.text.trim(),
|
|
province: _provinceController.text.trim().toUpperCase(),
|
|
));
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
return AlertDialog(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
|
title: Row(
|
|
children: [
|
|
CircleAvatar(
|
|
backgroundColor: theme.colorScheme.primaryContainer,
|
|
child: Icon(Icons.domain_add, color: theme.colorScheme.primary),
|
|
),
|
|
const SizedBox(width: 12),
|
|
const Expanded(
|
|
child: Text(
|
|
'Nuovo Centro Riparazioni',
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
content: SingleChildScrollView(
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextFormField(
|
|
controller: _nameController,
|
|
autofocus: true,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Nome Laboratorio *',
|
|
hintText: 'Es: riparazioni.it / Laboratorio Centrale',
|
|
prefixIcon: Icon(Icons.storefront),
|
|
),
|
|
validator: (v) => v == null || v.trim().isEmpty
|
|
? 'Campo obbligatorio'
|
|
: null,
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextFormField(
|
|
controller: _addressController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Indirizzo Spedizione *',
|
|
hintText: 'Es: Via Roma 15',
|
|
prefixIcon: Icon(Icons.location_on),
|
|
),
|
|
validator: (v) => v == null || v.trim().isEmpty
|
|
? 'Campo obbligatorio'
|
|
: null,
|
|
),
|
|
const SizedBox(height: 16),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
flex: 2,
|
|
child: TextFormField(
|
|
controller: _cityController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Città',
|
|
hintText: 'Es: Milano',
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: TextFormField(
|
|
controller: _zipController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'CAP',
|
|
hintText: '20100',
|
|
),
|
|
keyboardType: TextInputType.number,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: TextFormField(
|
|
controller: _provinceController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Prov.',
|
|
hintText: 'MI',
|
|
),
|
|
textCapitalization: TextCapitalization.characters,
|
|
maxLength: 2,
|
|
buildCounter: (
|
|
_, {
|
|
required currentLength,
|
|
required isFocused,
|
|
maxLength,
|
|
}) => null,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Annulla'),
|
|
),
|
|
FilledButton.icon(
|
|
onPressed: _submit,
|
|
icon: const Icon(Icons.check),
|
|
label: const Text('Salva e Seleziona'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|