When the user selects an added product to the invoice, an alert dialog containing an quantity TextField appears so he can change the quantity desired for the product, changing the quantity manually in the TextFormFiels works fine, but changing it using minus button makes the application closes, the only message in the console is : Lost connection to device.
class InputNumberAlertDialog extends StatefulWidget {
const InputNumberAlertDialog(
{super.key, this.title, this.subTitle, this.initialValue});
final String? title;
final String? subTitle;
final double? initialValue;
@override
State<InputNumberAlertDialog> createState() => _InputNumberAlertDialogState();
}
class _InputNumberAlertDialogState extends State<InputNumberAlertDialog> {
double val = 0;
final TextEditingController _controller = TextEditingController();
@override
void initState() {
val = widget.initialValue ?? 0;
_controller.text = val.toString();
super.initState();
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text("${widget.title}"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(widget.subTitle ?? ""),
TextFormField(
controller: _controller,
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
decoration: InputDecoration(
prefixIcon: IconButton(
onPressed: () {
setState(() {
val--;
_controller.text = val.toString();
});
},
icon: const Icon(Icons.minimize),
),
suffixIcon: IconButton(
onPressed: () {},
icon: const Icon(Icons.add),
),
),
),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text("OK")),
TextButton(
onPressed: () {
Navigator.of(context).pop(false);
},
child: const Text("Annuler"))
],
);
}
}
New contributor
Aymane Laaroui is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.