title: Flutter: set parent widget state from child widget
body: <p>I am very beginner to Flutter and Dart. So I am trying to update the state of the parent widget, but to be honest after trying many different solutions none worked for me, or am I doing something wrong?</p>
  
  <p>What I'm trying to do is to update the <strong>_title</strong> in _BooksState() when the page changes in _Books() class.</p>
  
  <p>How do I set the _title state from the child (_Books()) widget?</p>
  
  <pre><code>class Books extends StatefulWidget {
    @override
    _BooksState createState() {
      return _BooksState();
    }
  }
  
  class _BooksState extends State&lt;Books&gt; {
    String _title = 'Books';
  
    _setTitle(String newTitle) {
      setState(() {
        _title = newTitle;
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(_title),
        ),
        body: _Books(),
      );
    }
  }
  
  class _Books extends StatelessWidget {
    final PageController _controller = PageController();
    final Stream&lt;QuerySnapshot&gt; _stream =
        Firestore.instance.collection('Books').orderBy('title').snapshots();
  
    _setAppBarTitle(String newTitle) {
      print(newTitle);
      // how do I set _title from here?
    }
  
    @override
    Widget build(BuildContext context) {
      return StreamBuilder&lt;QuerySnapshot&gt;(
        stream: _stream,
        builder: (BuildContext context, AsyncSnapshot&lt;QuerySnapshot&gt; snapshot) {
          final books = snapshot.data.documents;
          switch (snapshot.connectionState) {
            case ConnectionState.waiting:
              return Center(child: CircularProgressIndicator());
            default:
              return PageView.builder(
                controller: _controller,
                scrollDirection: Axis.horizontal,
                itemCount: books.length,
                itemBuilder: (context, index) {
                  final book = books[index];
                  return ListTile(
                    title: Text(book['title']),
                    subtitle: Text(book['author']),
                  );
                },
                onPageChanged: (index) {
                  _setAppBarTitle(books[index].data['title']);
                },
              );
          }
        },
      );
    }
  }
  </code></pre>