You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a button, on pressing the button the focus should go to the TextFieldTags so that the cursor blinks on the textfield. I tried creating a focus node and passed that focus note to the input field controller , that brings the focus to the TextFieldTags as soon button is pressed but it doesn't work as expected because the TextFieldTags is using its own focus node. How do I get the focus on the textfieldTags so that the cursor blinks on the textfield on a button press.
Here is the code snippet :
Stack(
children: [
TagsList(callback: (tags) {
selectedTagsList = tags;
},
focusNode: _tagsFocusNode,
),
if(_showAddTagButton)
APButton(
fixedSize: Size(100, 30),
onPressed: () {
setState(() {
_showAddTagButton = false;
});
_tagsFocusNode.requestFocus();
},
child: Text(
'+ Add Tag',
),
),
],
),
In the TextTagField I want to get the focus here is the code - child: TextFieldTags(
textEditingController: ttec,
focusNode: tfn,
textfieldTagsController: _controller,
textSeparators: const [' '],
letterCase: LetterCase.normal,
validator: (String tag) {
if (tagsList.contains(tag)) {
return null; // Allow the tag to be created
} else {
return 'Invalid Tag'; // Prevent the tag from being created
}
},
inputfieldBuilder:
(context, tec, fn, error, onChanged, onSubmitted) {
return ((context, sc, tags, onTagDelete) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: TextField(
controller: tec,
focusNode: fn,
......
The text was updated successfully, but these errors were encountered:
ektay
changed the title
How to show the cursor on the TagTextField when a button is pressed
How to move the focus to the TagTextField when a button is pressed
Mar 5, 2024
I have a button, on pressing the button the focus should go to the TextFieldTags so that the cursor blinks on the textfield. I tried creating a focus node and passed that focus note to the input field controller , that brings the focus to the TextFieldTags as soon button is pressed but it doesn't work as expected because the TextFieldTags is using its own focus node. How do I get the focus on the textfieldTags so that the cursor blinks on the textfield on a button press.
Here is the code snippet :
Stack(
children: [
TagsList(callback: (tags) {
selectedTagsList = tags;
},
focusNode: _tagsFocusNode,
),
if(_showAddTagButton)
APButton(
fixedSize: Size(100, 30),
onPressed: () {
setState(() {
_showAddTagButton = false;
});
_tagsFocusNode.requestFocus();
},
child: Text(
'+ Add Tag',
),
),
],
),
In the TextTagField I want to get the focus here is the code - child: TextFieldTags(
textEditingController: ttec,
focusNode: tfn,
textfieldTagsController: _controller,
textSeparators: const [' '],
letterCase: LetterCase.normal,
validator: (String tag) {
if (tagsList.contains(tag)) {
return null; // Allow the tag to be created
} else {
return 'Invalid Tag'; // Prevent the tag from being created
}
},
inputfieldBuilder:
(context, tec, fn, error, onChanged, onSubmitted) {
return ((context, sc, tags, onTagDelete) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: TextField(
controller: tec,
focusNode: fn,
......
The text was updated successfully, but these errors were encountered: