add submit

This commit is contained in:
2026-04-13 11:01:50 +02:00
parent 8f2086e3a3
commit 97604a81e5
3 changed files with 40 additions and 28 deletions

View File

@@ -11,6 +11,7 @@ class FluxTextField extends StatelessWidget {
final TextInputType? keyboardType; // Aggiunto per flessibilità final TextInputType? keyboardType; // Aggiunto per flessibilità
final int? minLines; final int? minLines;
final int? maxLines; final int? maxLines;
final Function(String)? onSubmitted;
const FluxTextField({ const FluxTextField({
super.key, // Usiamo super.key per Flutter moderno super.key, // Usiamo super.key per Flutter moderno
@@ -22,6 +23,7 @@ class FluxTextField extends StatelessWidget {
this.keyboardType, this.keyboardType,
this.minLines, this.minLines,
this.maxLines = 1, this.maxLines = 1,
this.onSubmitted,
}); });
@override @override
@@ -56,6 +58,7 @@ class FluxTextField extends StatelessWidget {
vertical: 16, vertical: 16,
), ),
), ),
onSubmitted: onSubmitted,
); );
} }
} }

View File

@@ -84,6 +84,7 @@ class _AuthScreenState extends State<AuthScreen> {
icon: Icons.lock_outline, icon: Icons.lock_outline,
isPassword: true, isPassword: true,
controller: _passwordController, controller: _passwordController,
onSubmitted: (_) => _submit(),
), ),
const SizedBox(height: 40), const SizedBox(height: 40),
@@ -93,16 +94,7 @@ class _AuthScreenState extends State<AuthScreen> {
width: double.infinity, width: double.infinity,
height: 56, height: 56,
child: ElevatedButton( child: ElevatedButton(
onPressed: isLoading onPressed: isLoading ? null : () => _submit(),
? null
: () {
context.read<AuthBloc>().add(
LoginRequested(
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
),
);
},
child: isLoading child: isLoading
? const SizedBox( ? const SizedBox(
height: 24, height: 24,
@@ -151,4 +143,13 @@ class _AuthScreenState extends State<AuthScreen> {
), ),
); );
} }
void _submit() {
context.read<AuthBloc>().add(
LoginRequested(
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
),
);
}
} }

View File

@@ -18,6 +18,7 @@ void showBrandDialog(BuildContext context, {BrandModel? brand}) {
labelText: "Nome Brand", labelText: "Nome Brand",
hintText: "es. Apple, Samsung...", hintText: "es. Apple, Samsung...",
), ),
onSubmitted: (_) => _submitBrand(controller, context, brand),
), ),
actions: [ actions: [
TextButton( TextButton(
@@ -25,15 +26,7 @@ void showBrandDialog(BuildContext context, {BrandModel? brand}) {
child: const Text("Annulla"), child: const Text("Annulla"),
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () => _submitBrand(controller, context, brand),
if (controller.text.isNotEmpty) {
context.read<ProductCubit>().saveBrand(
controller.text,
id: brand?.id,
);
Navigator.pop(context);
}
},
child: const Text("Salva"), 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<ProductCubit>().saveBrand(controller.text, id: brand?.id);
Navigator.pop(context);
}
}
void showModelDialog(BuildContext context, {ModelModel? model}) { void showModelDialog(BuildContext context, {ModelModel? model}) {
final controller = TextEditingController(text: model?.name); final controller = TextEditingController(text: model?.name);
@@ -55,6 +59,7 @@ void showModelDialog(BuildContext context, {ModelModel? model}) {
labelText: "Nome Modello", labelText: "Nome Modello",
hintText: "es. iPhone 15, Galaxy S24...", hintText: "es. iPhone 15, Galaxy S24...",
), ),
onSubmitted: (_) => _submitModel(controller, context, model),
), ),
actions: [ actions: [
TextButton( TextButton(
@@ -62,15 +67,7 @@ void showModelDialog(BuildContext context, {ModelModel? model}) {
child: const Text("Annulla"), child: const Text("Annulla"),
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () => _submitModel(controller, context, model),
if (controller.text.isNotEmpty) {
context.read<ProductCubit>().saveModel(
controller.text,
id: model?.id,
);
Navigator.pop(context);
}
},
child: const Text("Salva"), 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<ProductCubit>().saveModel(controller.text, id: model?.id);
Navigator.pop(context);
}
}
void confirmToggle(BuildContext context, String title, VoidCallback onConfirm) { void confirmToggle(BuildContext context, String title, VoidCallback onConfirm) {
showDialog( showDialog(
context: context, context: context,