Created
September 26, 2019 03:25
-
-
Save this-is-richard/918a63933dc1836a17165d8e5a2cc49a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class TouchedDetector extends StatefulWidget { | |
final Function(FocusNode, bool) renderer; | |
const TouchedDetector({Key key, this.renderer}) : super(key: key); | |
@override | |
_TouchedDetectorState createState() => _TouchedDetectorState(); | |
} | |
class _TouchedDetectorState extends State<TouchedDetector> { | |
final _focusNode = FocusNode(); | |
List<bool> _state = []; | |
@override | |
void initState() { | |
super.initState(); | |
_focusNode.addListener(() { | |
setState(() { | |
_state.add(_focusNode.hasFocus); | |
}); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
final _autoValidate = _state.length >= 2; | |
final child = widget.renderer(_focusNode, _autoValidate); | |
return Container( | |
child: child, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment