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

Commit 59dda61

Browse files
authored
Merge pull request #17 from DutchCodingCompany/feature/fix_android_losing_focus
Bug fix where android keyboard loses focus
2 parents ff35599 + b756e06 commit 59dda61

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)