Skip to content
Permalink
Browse files

Minor cleanup fixes for when controller and focus node come from the …

…parent widget
  • Loading branch information...
jpeiffer committed Jul 15, 2019
1 parent 4d51b01 commit 3960a5e874ce6dc0af0abb108e7ce4de0880302e
Showing with 17 additions and 4 deletions.
  1. +17 −4 lib/pin_code_text_field.dart
@@ -199,20 +199,28 @@ class PinCodeTextFieldState extends State<PinCodeTextField> {

_initTextController();
_calculateStrList();
widget.controller?.addListener(() {
widget.controller?.addListener(_controllerListener);
focusNode?.addListener(_focusListener);
}

void _controllerListener() {
if (mounted == true) {
setState(() {
_initTextController();
});

if (widget.onTextChanged != null) {
widget.onTextChanged(widget.controller.text);
}
});
focusNode?.addListener(() {
}
}

void _focusListener() {
if (mounted == true) {
setState(() {
hasFocus = focusNode.hasFocus;
});
});
}
}

bool _isNumeric(String s) {
@@ -250,7 +258,12 @@ class PinCodeTextFieldState extends State<PinCodeTextField> {
// Only dispose the focus node if it's internal. Don't dispose the passed
// in focus node as it's owned by the parent not this child widget.
focusNode?.dispose();
} else {
focusNode.removeListener(_focusListener);
}

widget.controller?.removeListener(_controllerListener);

super.dispose();
}

0 comments on commit 3960a5e

Please sign in to comment.
You can’t perform that action at this time.