title: Access state from parent - flutter
body: <p>I try to create a basic notes app to study about flutter and I do not quite understand how to notify my <code>NotesContainer</code> that the button has been pressed. I tried to create a ref to it but the adding function is in the state class that I'm not sure how to reach.</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  class HomePage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      final NotesContainer Notes = new NotesContainer();
      return Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: Text('My Notes'),
          backgroundColor: Color.fromRGBO(223, 175, 117, 1),
          actions: &lt;Widget&gt;[
            IconButton(
              icon: Icon(Icons.add),
              onPressed: (){
                Notes.add()
              },
            )
          ],
        ),
        body: Notes
      );
    }
  }
  
  class NoteData{
    String title;
    String content;
  
    NoteData(this.title, this.content);
    NoteData.noContent(t){
      title = t;
      content ='';
    }
  }
  
  class NotesContainer extends StatefulWidget{
    @override
  
    State&lt;StatefulWidget&gt; createState(){
      return new _NotesContainer();
    }
  
  }
  
  class _NotesContainer extends State&lt;NotesContainer&gt;{
    final _notes = &lt;NoteData&gt;[new NoteData('title','thing to do'), new NoteData('title2','thing to do2')];
  
    void add({String title='1'}){ //just to test adding 
      setState(() {
         _notes.add(new NoteData.noContent(title));
      });
    }
  
    Widget build(BuildContext context){
      return _buildNotesContainer();
    }
  
    _buildNotesContainer(){
  
      return new ListView.separated(
        itemCount: _notes.length,
        separatorBuilder: (BuildContext context, int index) =&gt; Divider(),
        itemBuilder: (BuildContext context, int index) {
          return ListTile(
            title: Text(_notes[index].title), 
          );
        },
        padding: const EdgeInsets.all(10.0),
      );
    }
  }
  </code></pre>
  
  <p>I guess the solution is somehow exposing the _function in the <code>_NotesContainer</code> via the stateful <code>NotesContainer</code> class. I wonder if there is a more elegant solution for this. </p>
  
  <p>Thanks, Or  </p>