title: Dart / flutter: how to build a form with multiple user input fields easily
body: <p>I want to build a form where I have multiple <code>TextField</code> widgets, and want to have a button that composes and e-mail when pressed, by passing the data gathered from these fields.</p>
  
  <p>For this, I started building an <code>InheritedWidget</code> to contain <code>TextField</code>-s, and based on the action passed in the constructor - functionality not yet included in the code below - it would return a different text from via <code>toString</code> method override.</p>
  
  <p>As I understood, an <code>InheritedWidget</code> holds it's value as long as it is part of the current Widget tree (so, for example, if I navigate from the form it gets destroyed and the value is lost).</p>
  
  <p>Here is how I built my TextForm using InheritedWidget:</p>
  
  <pre><code>class TextInheritedWidget extends InheritedWidget {
    const TextInheritedWidget({
      Key key,
      this.text,
      Widget child}) : super(key: key, child: child);
  
    final String text;
  
    @override
    bool updateShouldNotify(TextInheritedWidget old) {
      return text != old.text;
    }
  
    static TextInheritedWidget of(BuildContext context) {
      return context.inheritFromWidgetOfExactType(TextInheritedWidget);
    }
  
  }
  
  class TextInputWidget extends StatefulWidget {
    @override
    createState() =&gt; new TextInputWidgetState();
  }
  
  class TextInputWidgetState extends State&lt;TextInputWidget&gt; {
    String text;
    TextEditingController textInputController = new TextEditingController();
  
    @override
    Widget build(BuildContext context) {
      return new TextInheritedWidget(
        text: text,
        child: new TextField(
          controller: textInputController,
          decoration: new InputDecoration(
            hintText: adoptionHintText
          ),
          onChanged: (text) {
            setState(() {
              this.text = textInputController.text;
            });
          },
        ),
      );
    }
  
    @override
    String toString({DiagnosticLevel minLevel: DiagnosticLevel.debug}) {
      // TODO: implement toString
      return 'Név: ' + text;
    }
  }
  </code></pre>
  
  <p>And here is the button that launches the e-mail sending:</p>
  
  <pre><code>TextInputWidget nameInputWidget = new TextInputWidget();
    TextInheritedWidget inherited = new TextInheritedWidget();
  
    @override
    Widget build(BuildContext context) {
      return new Scaffold(
        appBar: new AppBar(
          title: new Text('Örökbefogadás'),
        ),
        body: new Container(
          padding: const EdgeInsets.all(5.0),
          child: new ListView(
            children: &lt;Widget&gt;[
              new Text('Név:', style: infoText16BlackBold,),
              nameInputWidget,
              new FlatButton(onPressed: () {
                launchAdoptionEmail(nameInputWidget.toString(), 'kutya');
              },
                  child: new Text('Jelentkezem'))
  
            ],
          ),
        ),
  
      );
    }
  </code></pre>
  
  <p>My problem is that the <code>nameInputWidget.toString()</code> simply returns TextInputWidget (class name) and I can't seem to find a way to access the <code>TextInputWidgetState.toString()</code> method. </p>
  
  <p>I know that <code>TextInheritedWidget</code> holds the <code>text</code> value properly, but I'm not sure how I could access that via my <code>nameInputWidget</code> object.</p>
  
  <p>Shouldn't the <code>TextInputWidget</code> be able to access the data via the context the <code>InheritedWidget</code> uses to determine which <code>Widget</code> to update and store the value of?</p>