Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit b756e06

Browse files
committed
Use clear instead of override the text of the pin texteditingcontroller.
When override android loses focus on the textediting.
1 parent 7423e9e commit b756e06

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/src/presentation/widgets/pin_input_widget.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class PinInputWidget extends StatefulWidget {
3131
class _PinInputWidgetState extends State<PinInputWidget> {
3232
late final TextEditingController controller;
3333
late final FocusNode focusNode;
34+
3435
@override
3536
void initState() {
3637
super.initState();
@@ -42,10 +43,17 @@ class _PinInputWidgetState extends State<PinInputWidget> {
4243
focusNode.addListener(() => setState(() {}));
4344
}
4445

46+
@override
47+
void dispose() {
48+
focusNode.dispose();
49+
controller.dispose();
50+
super.dispose();
51+
}
52+
4553
@override
4654
Widget build(BuildContext context) {
4755
if (controller.text != widget.value) {
48-
controller.text = widget.value;
56+
controller.clear();
4957
}
5058
return Row(
5159
mainAxisSize: MainAxisSize.min,
@@ -77,10 +85,9 @@ class _PinInputWidgetState extends State<PinInputWidget> {
7785
focusNode: focusNode,
7886
keyboardType: TextInputType.number,
7987
maxLength: widget.pinLength,
80-
onChanged: (text) async {
88+
onChanged: (text) {
8189
widget.onInput(text);
82-
if (text.length == widget.pinLength &&
83-
focusNode.hasFocus == true) {
90+
if (text.length == widget.pinLength && focusNode.hasFocus == true) {
8491
widget.nextFocusNode?.requestFocus();
8592
}
8693
},

0 commit comments

Comments
 (0)