Created
July 17, 2019 06:25
-
-
Save trongdth/b553d1f1acf7d2e7e9eaaacd115aefe1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
void initState() { | |
... | |
_focusNode.addListener(() { | |
if (!_focusNode.hasFocus) { | |
setState(() { | |
if (txtController.text.isEmpty) { | |
isShowHintText = true; | |
} else { | |
isShowHintText = false; | |
} | |
}); | |
} | |
}); | |
super.initState(); | |
} | |
... | |
TextField( | |
focusNode: _focusNode, | |
style: widget.txtStyle, | |
textAlign: TextAlign.left, | |
controller: txtController, | |
decoration: InputDecoration( | |
border: (widget.showBorder) ? UnderlineInputBorder() : InputBorder.none, | |
hintText: (isShowHintText) ? widget.hintText : '', | |
), | |
onTap: () => _onTap(), | |
onChanged: (value) => _onChanged(value), | |
onEditingComplete: () => _onComplete(), | |
); | |
... | |
void _onTap() { | |
setState(() { | |
isShowHintText = false; | |
}); | |
} | |
void _onChanged(String value) { | |
if (widget.onTxtChanged != null) { | |
widget.onTxtChanged(value); | |
} | |
setState(() {}); | |
} | |
void _onComplete() { | |
setState(() { | |
if (txtController.text.isEmpty) { | |
isShowHintText = true; | |
} else { | |
isShowHintText = false; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment