title: How to pass data from TextFormField to List in flutter?
body: <p>I have the following working code:</p>
  
  <pre><code>class Submit extends StatefulWidget {
    @override
    _SubmitState createState() =&gt; new _SubmitState();
  }
  
  class _SubmitState extends State&lt;Submit&gt; {
    final scaffoldKey = new GlobalKey&lt;ScaffoldState&gt;();
    final formKey = new GlobalKey&lt;FormState&gt;();
    final myController = new TextEditingController();
    double _w;
  
    @override
    void dispose() {
      // Clean up the controller when the Widget is removed from the Widget tree
      myController.dispose();
      super.dispose();
    }
  
    void _submit() {
      final form = formKey.currentState;
  
      if (form.validate()) {
        form.save();
        _performSubmit();
      }
    }
  
    void _performSubmit() {
  
      final double data = double.parse(myController.text)*(2);
      var route = new MaterialPageRoute(builder: (BuildContext context) =&gt;
      new NextPage(w1: data.toStringAsFixed(3)),
      );
  
      Navigator.of(context).push(route);
    }
  
    @override
    Widget build(BuildContext context) {
  
      void _restart() {
        Navigator.of(context).push(new MaterialPageRoute(
            builder: (BuildContext context) =&gt; new HomePage()));
      }
  
      return new Scaffold(
        key: scaffoldKey,
        appBar: new AppBar(
          actions: &lt;Widget&gt;[
          ],
          title: new Text('Next Page'),
        ),
        body:  new Form(
            key: formKey,
            child: new Column(
              children: [
                new TextFormField(
                  controller: myController,
                  keyboardType: TextInputType.numberWithOptions(decimal: true),
                  onSaved: (val) =&gt; _w = double.parse(val),
                ),
                new RaisedButton(
                  onPressed: _submit,
                  child: new Text(
                    'Next Page',
                  ),
                )
              ],
            ),
          ),
      );
    }
  }
  
  
  
  class NextPage extends StatefulWidget {
  
    final String w1;
  
    NextPage({Key key, this.w1}) : super (key: key);
  
    @override
    _NextPageState createState() =&gt; _NextPageState();
  }
  
  
  class _NextPageState extends State&lt;NextPage&gt; {
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: new AppBar(
            title: new Text("Second page")
        ),
        body: new Text("${widget.w1}")
      );
    }
  }
  </code></pre>
  
  <p>Here I pass a variable multiplied by two (called <code>w1</code>), and then I show it on the next screen (<code>NextScreen</code>) with <code>Text</code>. But I want the result on a List, which is defined with other class as I show next. I would like to show the value of the variable <code>w1</code> where the text <code>1.1</code> is (inside <code>List&lt;Entry&gt;</code>). I have my full code next, but I don´t know how to pass the variable. If I write <code>new Entry('${widget.w1}',),</code> I get <code>undefined name widget</code>.</p>
  
  <p>How could I pass my variable to that list?</p>
  
  <pre><code>class Submit extends StatefulWidget {
    @override
    _SubmitState createState() =&gt; new _SubmitState();
  }
  
  class _SubmitState extends State&lt;Submit&gt; {
    final scaffoldKey = new GlobalKey&lt;ScaffoldState&gt;();
    final formKey = new GlobalKey&lt;FormState&gt;();
    final myController = new TextEditingController();
    double _w;
  
    @override
    void dispose() {
      // Clean up the controller when the Widget is removed from the Widget tree
      myController.dispose();
      super.dispose();
    }
  
    void _submit() {
      final form = formKey.currentState;
  
      if (form.validate()) {
        form.save();
        _performSubmit();
      }
    }
  
    void _performSubmit() {
  
      final double data = double.parse(myController.text)*(2);
      var route = new MaterialPageRoute(builder: (BuildContext context) =&gt;
      new NextPage(w1: data.toStringAsFixed(3)),
      );
  
      Navigator.of(context).push(route);
    }
  
    @override
    Widget build(BuildContext context) {
  
      void _restart() {
        Navigator.of(context).push(new MaterialPageRoute(
            builder: (BuildContext context) =&gt; new HomePage()));
      }
  
      return new Scaffold(
        key: scaffoldKey,
        appBar: new AppBar(
          actions: &lt;Widget&gt;[
          ],
          title: new Text('Next Page'),
        ),
        body:  new Form(
            key: formKey,
            child: new Column(
              children: [
                new TextFormField(
                  controller: myController,
                  keyboardType: TextInputType.numberWithOptions(decimal: true),
                  onSaved: (val) =&gt; _w = double.parse(val),
                ),
                new RaisedButton(
                  onPressed: _submit,
                  child: new Text(
                    'Next Page',
                  ),
                )
              ],
            ),
          ),
      );
    }
  }
  
  
  
  class NextPage extends StatefulWidget {
  
    final String w1;
  
    NextPage({Key key, this.w1}) : super (key: key);
  
    @override
    _NextPageState createState() =&gt; _NextPageState();
  }
  
  
  class _NextPageState extends State&lt;NextPage&gt; {
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: new AppBar(
            title: new Text("Second page")
        ),
        body: new ListView.builder(
          itemBuilder: (BuildContext context, int index) =&gt;
          new EntryItem(data[index]),
          itemCount: data.length,
        ),
      );
    }
  }
  
  
  // One entry in the multilevel list displayed by this app.
  class Entry {
    Entry(this.title, [this.children = const &lt;Entry&gt;[]]);
  
    final String title;
    final List&lt;Entry&gt; children;
  }
  
  // The entire multilevel list displayed by this app.
  
  List&lt;Entry&gt; data = &lt;Entry&gt;[
    new Entry(
      'First',
      &lt;Entry&gt;[
        new Entry(
          '1.1',
        ),
      ],
    ),
  ];
  
  // Displays one Entry. If the entry has children then it's displayed
  // with an ExpansionTile.
  class EntryItem extends StatelessWidget {
    const EntryItem(this.entry);
  
    final Entry entry;
  
    Widget _buildTiles(Entry root) {
      if (root.children.isEmpty)
        return new ListTile(
            title: new Text(root.title));
  
      return new ExpansionTile(
        key: new PageStorageKey&lt;Entry&gt;(root),
        title: new Text(root.title,),
        children: root.children.map(_buildTiles).toList(),
      );
    }
  
    @override
    Widget build(BuildContext context) {
      return _buildTiles(entry);
    }
  }
  </code></pre>