|
|
|
@ -4,7 +4,6 @@ import 'package:youmazgestion/Models/client.dart'; |
|
|
|
|
|
|
|
import '../Services/stock_managementDatabase.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class ClientFormController extends GetxController { |
|
|
|
final _formKey = GlobalKey<FormState>(); |
|
|
|
|
|
|
|
@ -88,7 +87,9 @@ class ClientFormController extends GetxController { |
|
|
|
prenom: _prenomController.text.trim(), |
|
|
|
email: _emailController.text.trim(), |
|
|
|
telephone: _telephoneController.text.trim(), |
|
|
|
adresse: _adresseController.text.trim().isEmpty ? null : _adresseController.text.trim(), |
|
|
|
adresse: _adresseController.text.trim().isEmpty |
|
|
|
? null |
|
|
|
: _adresseController.text.trim(), |
|
|
|
dateCreation: DateTime.now(), |
|
|
|
); |
|
|
|
|
|
|
|
@ -98,7 +99,6 @@ class ClientFormController extends GetxController { |
|
|
|
// Procéder avec la commande |
|
|
|
Get.back(); |
|
|
|
_submitOrderWithClient(clientToUse); |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
Get.snackbar( |
|
|
|
'Erreur', |
|
|
|
@ -116,6 +116,7 @@ class ClientFormController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
// Widget pour le formulaire avec auto-completion |
|
|
|
// ignore: unused_element |
|
|
|
void _showClientFormDialog() { |
|
|
|
final controller = Get.put(ClientFormController()); |
|
|
|
|
|
|
|
@ -168,7 +169,8 @@ void _showClientFormDialog() { |
|
|
|
), |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
Icon(Icons.check_circle, color: Colors.green.shade600), |
|
|
|
Icon(Icons.check_circle, |
|
|
|
color: Colors.green.shade600), |
|
|
|
const SizedBox(width: 8), |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
@ -191,7 +193,8 @@ void _showClientFormDialog() { |
|
|
|
_buildTextFormField( |
|
|
|
controller: controller._nomController, |
|
|
|
label: 'Nom', |
|
|
|
validator: (value) => value?.isEmpty ?? true ? 'Veuillez entrer un nom' : null, |
|
|
|
validator: (value) => |
|
|
|
value?.isEmpty ?? true ? 'Veuillez entrer un nom' : null, |
|
|
|
onChanged: (value) { |
|
|
|
if (controller.selectedClient.value != null) { |
|
|
|
controller.selectedClient.value = null; |
|
|
|
@ -203,7 +206,9 @@ void _showClientFormDialog() { |
|
|
|
_buildTextFormField( |
|
|
|
controller: controller._prenomController, |
|
|
|
label: 'Prénom', |
|
|
|
validator: (value) => value?.isEmpty ?? true ? 'Veuillez entrer un prénom' : null, |
|
|
|
validator: (value) => value?.isEmpty ?? true |
|
|
|
? 'Veuillez entrer un prénom' |
|
|
|
: null, |
|
|
|
onChanged: (value) { |
|
|
|
if (controller.selectedClient.value != null) { |
|
|
|
controller.selectedClient.value = null; |
|
|
|
@ -217,8 +222,10 @@ void _showClientFormDialog() { |
|
|
|
label: 'Email', |
|
|
|
keyboardType: TextInputType.emailAddress, |
|
|
|
validator: (value) { |
|
|
|
if (value?.isEmpty ?? true) return 'Veuillez entrer un email'; |
|
|
|
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(value!)) { |
|
|
|
// if (value?.isEmpty ?? true) return 'Veuillez entrer un email'; |
|
|
|
if (value?.isEmpty ?? true) return null; |
|
|
|
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$') |
|
|
|
.hasMatch(value!)) { |
|
|
|
return 'Email invalide'; |
|
|
|
} |
|
|
|
return null; |
|
|
|
@ -237,7 +244,9 @@ void _showClientFormDialog() { |
|
|
|
controller: controller._telephoneController, |
|
|
|
label: 'Téléphone', |
|
|
|
keyboardType: TextInputType.phone, |
|
|
|
validator: (value) => value?.isEmpty ?? true ? 'Veuillez entrer un téléphone' : null, |
|
|
|
validator: (value) => value?.isEmpty ?? true |
|
|
|
? 'Veuillez entrer un téléphone' |
|
|
|
: null, |
|
|
|
onChanged: (value) { |
|
|
|
if (controller.selectedClient.value != null) { |
|
|
|
controller.selectedClient.value = null; |
|
|
|
@ -252,7 +261,9 @@ void _showClientFormDialog() { |
|
|
|
controller: controller._adresseController, |
|
|
|
label: 'Adresse', |
|
|
|
maxLines: 2, |
|
|
|
validator: (value) => value?.isEmpty ?? true ? 'Veuillez entrer une adresse' : null, |
|
|
|
validator: (value) => value?.isEmpty ?? true |
|
|
|
? 'Veuillez entrer une adresse' |
|
|
|
: null, |
|
|
|
onChanged: (value) { |
|
|
|
if (controller.selectedClient.value != null) { |
|
|
|
controller.selectedClient.value = null; |
|
|
|
@ -288,7 +299,8 @@ void _showClientFormDialog() { |
|
|
|
), |
|
|
|
), |
|
|
|
const SizedBox(height: 8), |
|
|
|
...controller.suggestedClients.map((client) => |
|
|
|
...controller.suggestedClients.map( |
|
|
|
(client) => |
|
|
|
_buildClientSuggestionTile(client, controller), |
|
|
|
), |
|
|
|
], |
|
|
|
@ -349,7 +361,8 @@ Widget _buildSearchSection(ClientFormController controller) { |
|
|
|
} |
|
|
|
|
|
|
|
// Widget pour afficher une suggestion de client |
|
|
|
Widget _buildClientSuggestionTile(Client client, ClientFormController controller) { |
|
|
|
Widget _buildClientSuggestionTile( |
|
|
|
Client client, ClientFormController controller) { |
|
|
|
return Card( |
|
|
|
margin: const EdgeInsets.only(bottom: 8), |
|
|
|
child: ListTile( |
|
|
|
|