I am using a Linkable to highlight web links, phone numbers, and email addresses from what the user types into a textfield. The first problem is that the linkable does not take textfield in, it only takes in a Text. So, my solution was to show TextField only when user is typing, and replace Textfield with what the user typed in as Text when user is not typing. The second problem is that whenever the textfield is visible, at first it does not show the keyboard or the cursor, even when I can verify that its focus is true. How can I show cursor every time the textfield pops up? I even set showcursor to true and it still does not work. In another post I read that using a timer with a delay would solve the problem, so I did that but it still does not work.
FocusNode _focusNode = FocusNode();
@override
Widget build(BuildContext context) {
...
return GestureDetector(
onTap: () {
FocusNode currentFocus = FocusScope.of(context);
if (currentFocus.hasFocus) {
currentFocus.unfocus();
}
},
child: Column(
children: <Widget>[
Visibility(
visible: _focusNode.hasFocus,
child: TextField(
focusNode: _focusNode,
showCursor: true,
controller: _contentTextController,
),
InkWell(
child: Linkable(
text: "testing",
onTap: () async {
FocusScope.of(context).requestFocus(_focusNode);
// FocusScope.of(context).requestFocus(_focusNode);
// Timer(const Duration(milliseconds: 1000), () {
// FocusScope.of(context).requestFocus(_focusNode);
// _focusNode.requestFocus();
// });
await Future.delayed(
Duration(milliseconds: 10)
);
Timer(const Duration(milliseconds: 10), () {
setState(() {
print(_focusNode.hasPrimaryFocus);
//showTextEditor = !showTextEditor;
});
});
}
),
],
Here is my code.