add submit
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user