title: Flutter: How to save user's input from a ListView.builder of TextFields
body: <p>I'm trying to <strong>save user's input</strong> from a <em>ListView.builder</em> of <em>TextFields</em> in a list of objects <strong>when he presses a button</strong>. <a href="https://i.stack.imgur.com/mmAlE.png" rel="nofollow noreferrer">Screnshot</a></p>
  
  <p>I would like that when the user presses the button save, all the hello words were storaged as the text property of my object.</p>
  
  <p>That is my code:</p>
  
  <pre><code>class Home extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      ListData listData = Provider.of&lt;ListData&gt;(context, listen: false);
  
      return Scaffold(
        appBar: AppBar(
          title: Text('Add Textfields'),
          actions: &lt;Widget&gt;[
            FlatButton(
              color: Colors.red,
              onPressed: () {},
              child: Text('Save'),
            ),
          ],
        ),
        body: ListView(
          children: &lt;Widget&gt;[
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 50),
              child: TextFieldBuilder(),
            ),
            SizedBox(height: 50),
            FlatButton(
              onPressed: () {
                listData.addTextField();
              },
              child: Text(
                'Add',
                style: TextStyle(
                  letterSpacing: 4,
                  fontWeight: FontWeight.w900,
                  fontSize: 16,
                ),
              ),
            ),
          ],
        ),
      );
    }
  }
  </code></pre>
  
  <p>The Builderclass:</p>
  
  <pre><code>class TextFieldBuilder extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Consumer&lt;ListData&gt;(
        builder: (context, listData, child) {
          return ListView.builder(
            itemCount: listData.textFieldList.length,
            itemBuilder: (context, index) {
              return TextFieldWidget(index: index);
            },
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
          );
        },
      );
    }
  }
  </code></pre>
  
  <p>TextFieldWidget:</p>
  
  <pre><code>class TextFieldWidget extends StatelessWidget {
    final int index;
  
    TextFieldWidget({this.index});
  
    @override
    Widget build(BuildContext context) {
      return TextField(
        textAlign: TextAlign.center,
      );
    }
  }
  </code></pre>
  
  <p>And the <strong>list of objects</strong>:</p>
  
  <pre><code>class TextFieldData {
    String text;
  
    TextFieldData({this.text});
  }
  
  class ListData extends ChangeNotifier {
    List&lt;TextFieldData&gt; textFieldList = [];
  
    void addTextField() {
      textFieldList.add(TextFieldData());
      notifyListeners();
    }
  }
  </code></pre>