skip to Main Content

If I use textfield at Flutter, for example:

TextField(
  decoration: InputDecoration( 
    border: OutlineInputBorder(),
    hintText: 'Enter a search term',
  ),
)

and I want to have tag like I do when I create iOS textField

@IBOutlet weak var name1TextField: UITextField!
name1TextField.tag = 11

I do not have tag property in Flutter, is there any other way to create iOS tag at Flutter?

2

Answers


  1. In this issue, you can achieve similar functionality to the tag property of iOS UITextField by using a combination of key and FocusNode.

    The key property uniquely identifies widgets in Flutter and FocusNode is used to manage the focus of a widget. You can assign a unique key to your TextField and use a FocusNode to associate additional data or properties. Here’s an example code,

    FocusNode name1FocusNode = FocusNode();
    
    TextField(
      key: Key('name1TextField'), // Unique key for the TextField
      decoration: InputDecoration(
        border: OutlineInputBorder(),
        hintText: 'Enter a search term',
      ),
      focusNode: name1FocusNode, // Associate a FocusNode
    );
    

    With this setup, you can manage the TextField using the name1FocusNode. For instance, you can listen to focus changes, manage focus movement, and associate additional data or properties with this specific TextField.

    Login or Signup to reply.
  2. Please just add textfield_tags dart package to your project.

    Please check this link: https://pub.dev/packages/textfield_tags

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search