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

@@ -84,6 +84,7 @@ class _AuthScreenState extends State<AuthScreen> {
icon: Icons.lock_outline,
isPassword: true,
controller: _passwordController,
onSubmitted: (_) => _submit(),
),
const SizedBox(height: 40),
@@ -93,16 +94,7 @@ class _AuthScreenState extends State<AuthScreen> {
width: double.infinity,
height: 56,
child: ElevatedButton(
onPressed: isLoading
? null
: () {
context.read<AuthBloc>().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<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",
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<ProductCubit>().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<ProductCubit>().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<ProductCubit>().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<ProductCubit>().saveModel(controller.text, id: model?.id);
Navigator.pop(context);
}
}
void confirmToggle(BuildContext context, String title, VoidCallback onConfirm) {
showDialog(
context: context,