From 97604a81e5df1ca8a621f3004aef7b28f0b1a47d Mon Sep 17 00:00:00 2001 From: Mark M2 Macbook Date: Mon, 13 Apr 2026 11:01:50 +0200 Subject: [PATCH] add submit --- lib/core/widgets/flux_text_field.dart | 3 ++ lib/features/auth/ui/auth_screen.dart | 21 ++++----- lib/features/products/ui/product_dialogs.dart | 44 +++++++++++-------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/lib/core/widgets/flux_text_field.dart b/lib/core/widgets/flux_text_field.dart index eece7af..67a42af 100644 --- a/lib/core/widgets/flux_text_field.dart +++ b/lib/core/widgets/flux_text_field.dart @@ -11,6 +11,7 @@ class FluxTextField extends StatelessWidget { final TextInputType? keyboardType; // Aggiunto per flessibilità final int? minLines; final int? maxLines; + final Function(String)? onSubmitted; const FluxTextField({ super.key, // Usiamo super.key per Flutter moderno @@ -22,6 +23,7 @@ class FluxTextField extends StatelessWidget { this.keyboardType, this.minLines, this.maxLines = 1, + this.onSubmitted, }); @override @@ -56,6 +58,7 @@ class FluxTextField extends StatelessWidget { vertical: 16, ), ), + onSubmitted: onSubmitted, ); } } diff --git a/lib/features/auth/ui/auth_screen.dart b/lib/features/auth/ui/auth_screen.dart index addb7e8..5542665 100644 --- a/lib/features/auth/ui/auth_screen.dart +++ b/lib/features/auth/ui/auth_screen.dart @@ -84,6 +84,7 @@ class _AuthScreenState extends State { icon: Icons.lock_outline, isPassword: true, controller: _passwordController, + onSubmitted: (_) => _submit(), ), const SizedBox(height: 40), @@ -93,16 +94,7 @@ class _AuthScreenState extends State { width: double.infinity, height: 56, child: ElevatedButton( - onPressed: isLoading - ? null - : () { - context.read().add( - LoginRequested( - email: _emailController.text.trim(), - password: _passwordController.text.trim(), - ), - ); - }, + onPressed: isLoading ? null : () => _submit(), child: isLoading ? const SizedBox( height: 24, @@ -151,4 +143,13 @@ class _AuthScreenState extends State { ), ); } + + void _submit() { + context.read().add( + LoginRequested( + email: _emailController.text.trim(), + password: _passwordController.text.trim(), + ), + ); + } } diff --git a/lib/features/products/ui/product_dialogs.dart b/lib/features/products/ui/product_dialogs.dart index 4d4c419..d7ac56f 100644 --- a/lib/features/products/ui/product_dialogs.dart +++ b/lib/features/products/ui/product_dialogs.dart @@ -18,6 +18,7 @@ void showBrandDialog(BuildContext context, {BrandModel? brand}) { labelText: "Nome Brand", hintText: "es. Apple, Samsung...", ), + onSubmitted: (_) => _submitBrand(controller, context, brand), ), actions: [ TextButton( @@ -25,15 +26,7 @@ void showBrandDialog(BuildContext context, {BrandModel? brand}) { child: const Text("Annulla"), ), ElevatedButton( - onPressed: () { - if (controller.text.isNotEmpty) { - context.read().saveBrand( - controller.text, - id: brand?.id, - ); - Navigator.pop(context); - } - }, + onPressed: () => _submitBrand(controller, context, brand), child: const Text("Salva"), ), ], @@ -41,6 +34,17 @@ void showBrandDialog(BuildContext context, {BrandModel? brand}) { ); } +void _submitBrand( + TextEditingController controller, + BuildContext context, + BrandModel? brand, +) { + if (controller.text.trim().isNotEmpty) { + context.read().saveBrand(controller.text, id: brand?.id); + Navigator.pop(context); + } +} + void showModelDialog(BuildContext context, {ModelModel? model}) { final controller = TextEditingController(text: model?.name); @@ -55,6 +59,7 @@ void showModelDialog(BuildContext context, {ModelModel? model}) { labelText: "Nome Modello", hintText: "es. iPhone 15, Galaxy S24...", ), + onSubmitted: (_) => _submitModel(controller, context, model), ), actions: [ TextButton( @@ -62,15 +67,7 @@ void showModelDialog(BuildContext context, {ModelModel? model}) { child: const Text("Annulla"), ), ElevatedButton( - onPressed: () { - if (controller.text.isNotEmpty) { - context.read().saveModel( - controller.text, - id: model?.id, - ); - Navigator.pop(context); - } - }, + onPressed: () => _submitModel(controller, context, model), child: const Text("Salva"), ), ], @@ -78,6 +75,17 @@ void showModelDialog(BuildContext context, {ModelModel? model}) { ); } +void _submitModel( + TextEditingController controller, + BuildContext context, + ModelModel? model, +) { + if (controller.text.isNotEmpty) { + context.read().saveModel(controller.text, id: model?.id); + Navigator.pop(context); + } +} + void confirmToggle(BuildContext context, String title, VoidCallback onConfirm) { showDialog( context: context,