title: Callback from child to parent Flutter
body: <p>I am new to flutter. I am trying to separate the bottomappbar widget from my home screen. Thing is, it is I need to send back the index to the home screen file so I can switch the body of the screen. I've been learning BloC lately, but I think it is an overkill for this case, even though I am going to use it in other parts of the app (hopefully this is the right assumption). So, how can I send the index to the parent?</p>
  
  <p>Parent</p>
  
  <pre><code>class HomeScreen extends StatefulWidget {
    @override
    _HomeScreenState createState() =&gt; _HomeScreenState();
  }
  
  class _HomeScreenState extends State&lt;HomeScreen&gt; {
    int _selectedIndex = 0;
    final _bottomNavigationPages = [
      Screen1(),
      Screen2(),
    ];
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          iconTheme: IconThemeData(
            color: Colors.blueGrey,
          ),
          title:
              Text('xxx', style: new TextStyle(fontWeight: FontWeight.w400)),
        ),
        body: _bottomNavigationPages[_selectedIndex],
        bottomNavigationBar: HomeBottomAppBar(),
      );
    }
  }
  </code></pre>
  
  <p>Child</p>
  
  <pre><code>class HomeBottomAppBar extends StatefulWidget {
    @override
    _HomeBottomAppBarState createState() =&gt; _HomeBottomAppBarState();
  }
  
  class _HomeBottomAppBarState extends State&lt;HomeBottomAppBar&gt; {
    int _selectedIndex = 0;
  
    void _itemTapped(int index) {
      setState(() {
        _selectedIndex = index;
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return BottomAppBar(
        shape: CircularNotchedRectangle(),
        notchMargin: 5.0,
        clipBehavior: Clip.antiAlias,
        child: BottomNavigationBar(
          items: [
            BottomNavigationBarItem(
                icon: Icon(Icons.x), title: Text("1")),
            BottomNavigationBarItem(
                icon: Icon(Icons.x), title: Text("2")),
          ],
          currentIndex: _selectedIndex,
          onTap: _itemTapped,
        ),
      );
    }
  }
  </code></pre>
  
  <p>Also, I am going under the assumption that this is good practice. Maybe it is just better to have everything in the same file.</p>