title: Flutter send and show data between BottomNavigationBarItem
body: <p>I want to share and show data between <strong>BottomNavigationBarItems</strong></p>
  <p>It is my BottomNavigationBar page:</p>
  <pre><code>class BottomNavigationBarController extends StatefulWidget {
    @override
    _BottomNavigationBarControllerState createState() =&gt;
        _BottomNavigationBarControllerState();
  }
  
  class _BottomNavigationBarControllerState
      extends State&lt;BottomNavigationBarController&gt; {
    List&lt;Widget&gt; pages = [];
  
    @override
    void initState() {
      pages.add(HomePage(
        key: PageStorageKey('HomePage'),
      ));
      pages.add(MapPage(
        key: PageStorageKey('MapPage'),
      ));
      super.initState();
    }
  
    int _currentIndex = 0;
  
    Widget _bottomNavigationBar(int selectedIndex) =&gt; BottomNavigationBar(
          onTap: (int index) =&gt; setState(() =&gt; _currentIndex = index),
          currentIndex: selectedIndex,
          items: const &lt;BottomNavigationBarItem&gt;[
            BottomNavigationBarItem(icon: Icon(Icons.home), label: &quot;Home&quot;),
            BottomNavigationBarItem(icon: Icon(Icons.map), label: &quot;MapPage&quot;),
          ],
        );
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
            title: Text(&quot;iArrived&quot;),
            actions: _currentIndex != 1
                ? &lt;Widget&gt;[
                    IconButton(
                        icon: Icon(Icons.keyboard_arrow_right),
                        onPressed: () {
                          setState(() {
                            _currentIndex++;
                          });
                        })
                  ]
                : null),
        backgroundColor: Colors.white,
        bottomNavigationBar: _bottomNavigationBar(_currentIndex),
        body: IndexedStack(
          index: _currentIndex,
          children: pages,
        ),
      );
    }
  }
  </code></pre>
  <p>And I want to send my location from the <strong>MapPage</strong> to the <strong>HomePage</strong>.
  There is a function in the <strong>MapPage</strong> that is executed when the place change:</p>
  <pre><code>void _setLocation(LatLng latlng) {
      setState(() {
        lat = latlng.latitude;
        lng = latlng.longitude;
      });
    }
  </code></pre>
  <p>I think I have to call some function like a callback inside <em><strong>_setLocation()</strong></em> but I don't know how to implement it to show the location on my <strong>HomePage</strong> and have it refresh every time I change it.
  Thanks for the help.</p>
  <p>If your answer is to use <em><strong><a href="https://flutter.dev/docs/cookbook/persistence/key-value" rel="nofollow noreferrer">shared_preferences</a></strong></em> plugin, can you tell me how would you implement it? Because I tried it and it did not work for me.
  Thanks again.</p>