title: Changing focus of a dynamic list in flutter
body: <p>I have a function in flutter that opens a dialogue box with a list of text fields. The size of the list is determined by an argument to the function. I want to move focus to the next item as each is entered. I have tried creating a list of focus nodes to do this, but it doesn't work. Can someone point out what I am doing wrong. The code I have is shown below.</p>
  
  <pre><code>Future&lt;bool&gt; getPositions(BuildContext context, List&lt;String&gt; positions) async
  {
    int numPositions = positions.length ;
    final List&lt;FocusNode&gt; _fNodes = new List&lt;FocusNode&gt;.generate(numPositions, (_) =&gt; new FocusNode()) ;
    List&lt;Widget&gt; _widgets = new List&lt;Widget&gt;(numPositions) ;
  
    for (int i = 0 ; i &lt; numPositions ; ++i)
    {
      int p = i+1;
      _widgets[i] = new TextField(
            style: TextStyle(fontSize: 15.0),
            autofocus: true,
            focusNode: _fNodes[i],
            controller: TextEditingController(text: positions[i]),
            textInputAction: p &lt; numPositions ? TextInputAction.next : TextInputAction.done,
            onChanged: (value)
            {
              if (value.trim().isNotEmpty)
                positions[i] = value.trim();
            },
            onSubmitted: (value)
            {
              if (value.trim().isNotEmpty)
                positions[i] = value.trim();
              if (p &gt;= numPositions)
                Navigator.pop(context, true);
              else
                _fieldFocusChange(context, _fNodes[i], _fNodes[p]);
            },
      );
    }
  
    return showDialog&lt;bool&gt;(
      context: context,
      barrierDismissible: false,
      builder: (context)
      {
        return AlertDialog(
          title: Text("${Config.position} names", style: TextStyle(fontSize: 15.0)),
          titlePadding: EdgeInsets.all(10.0),
          contentPadding: EdgeInsets.all(0.0),
          content: new Container(
            width: double.maxFinite,
            height: 300.0,
            child: ListView(
              padding: const EdgeInsets.all(8.0),
              children: _widgets,
            ),
          ),
          actions: &lt;Widget&gt;[
            new FlatButton(
                child: const Text('CANCEL'),
                onPressed: ()
                {
                  Navigator.of(context).pop(false);
                }),
            new FlatButton(
                child: const Text("OK"),
                onPressed: ()
                {
                  Navigator.of(context).pop(true);
                }),
          ],
        );
      },
    );
  }
  
  void _fieldFocusChange(BuildContext context, FocusNode currentFocus,FocusNode nextFocus)
  {
    currentFocus.unfocus();
    FocusScope.of(context).requestFocus(nextFocus);
  }
  </code></pre>