title: how to call another http on each bottomnavigationbar in flutter
body: <p>I want to make codes for my app by flutter.</p>
  <p>Without bottomnavigationbar, my app works well.</p>
  <p>But there are some problem.
  I input bottomnavigationbar with _widgetOptions in my coding, it occured one problem.</p>
  <ol>
  <li>The program coundn't display http result, which was displayed without _widgetOptions.</li>
  </ol>
  <p><strong>This is my coding without _widgetOptions, it works well</strong></p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  import 'Services.dart';
  import 'Post.dart';
  
  void main() {
    runApp(MyApp());
  }
  
  class MyApp extends StatelessWidget {
    const MyApp({Key? key}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: MyHomePage(title: 'Flutter ListView'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    MyHomePage({Key? key, required this.title}) : super(key: key);
  
    final String title;
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    // late List&lt;Post&gt; posts;    //good
    late List&lt;Post&gt; posts = &lt;Post&gt;[];
    late bool loading;
  
    @override
    void initState() {
      super.initState();
      loading = true;
      Services.getPosts().then((list) {
        setState(() {
  
          posts
            ..clear()
            ..addAll(list);
  
          // posts = list;    //good
          loading = false;
        });
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(loading ? 'Loading...' : 'Posts'),
        ),
        body: Column(
          // mainAxisAlignment: MainAxisAlignment.spaceBetween,
          // crossAxisAlignment:CrossAxisAlignment.center,
          children: [
            Container(
              color: Colors.amber,
              child: Row(
                children: const [
                  Expanded(
                      child: Center(
                          child: Text('Date',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                  Expanded(
                      child: Center(
                          child: Text('Koreanwon/us\$',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                  Expanded(
                      child: Center(
                          child: Text('Koreanwon',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                  Expanded(
                      child: Center(
                          child: Text('US \$',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                ],
              ),
            ),
            Expanded(
              child: Center(
                child: Container(
                  child: ListView.builder(
                      itemCount: posts == null ? 0 : posts.length,
                      itemBuilder: (context, index) {
                        Post post = posts[index];
                        return Container(
                          decoration: const BoxDecoration(
                            border: Border(
                                bottom: BorderSide(color: Colors.blueAccent)),
                          ),
                          child: ListTile(
                            title: Row(
                              // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: &lt;Widget&gt;[
                                Expanded(child: Center(child: Text(post.date))),
                                Expanded(child: Center(child: Text(post.rate))),
                                Expanded(
                                    child: Center(child: Text(post.koreanwon))),
                                Expanded(child: Center(child: Text(post.dollar))),
                              ],
                            ),
                          ),
                          // ),
                        );
                      }),
                ),
              ),
            ),
          ],
        ),
      );
    }
  }
  </code></pre>
  <hr />
  <p><strong>This coding with bottomnavigationbar, could not display post result</strong></p>
  <pre><code>import 'package:flutter/material.dart';
  import 'Services.dart';
  import 'Post.dart';
  
  void main() {
    runApp(MyApp());
  }
  
  class MyApp extends StatelessWidget {
    const MyApp({Key? key}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: MyHomePage(title: 'Flutter ListView'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    MyHomePage({Key? key, required this.title}) : super(key: key);
  
    final String title;
  
    @override
    _MyHomePageState createState() =&gt; new _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    late List&lt;Post&gt; posts = &lt;Post&gt;[];
    late bool loading;
    late List _widgetOptions;
  
    @override
    void initState() {
      super.initState();
      loading = true;
      Services.getPosts().then((list) {
        setState(() {
          posts
            ..clear()
            ..addAll(list);
          // posts..addAll(list);
          loading = false;
        });
      });
      _widgetOptions = [
        Column(
          children: [
            Container(
              color: Colors.amber,
              child: Row(
                children: const [
                  Expanded(
                      child: Center(
                          child: Text('Date',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                  Expanded(
                      child: Center(
                          child: Text('Koreanwon/us\$',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                  Expanded(
                      child: Center(
                          child: Text('Koreanwon',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                  Expanded(
                      child: Center(
                          child: Text('US \$',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                ],
              ),
            ),
            Expanded(
              child: Center(
                child: Container(
                  child: ListView.builder(
                      itemCount: posts == null ? 0 : posts.length,
                      itemBuilder: (context, index) {
                        Post post = posts[index];
                        return Container(
                          decoration: const BoxDecoration(
                            border: Border(
                                bottom: BorderSide(color: Colors.blueAccent)),
                          ),
                          child: ListTile(
                            title: Row(
                              // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: &lt;Widget&gt;[
                                Expanded(child: Center(child: Text(post.date))),
                                Expanded(child: Center(child: Text(post.rate))),
                                Expanded(
                                    child: Center(child: Text(post.koreanwon))),
                                Expanded(child: Center(child: Text(post.dollar))),
                              ],
                            ),
                          ),
                        );
                      }),
                ),
              ),
            ),
          ],
        ),
  
  
        Column(
          children: [
            Container(
              color: Colors.amber,
              child: Row(
                children: const [
                  Expanded(
                      child: Center(
                          child: Text('Date',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                  Expanded(
                      child: Center(
                          child: Text('Koreanwon/us\$',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                  Expanded(
                      child: Center(
                          child: Text('Koreanwon',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                  Expanded(
                      child: Center(
                          child: Text('US \$',
                              style: TextStyle(
                                height: 2.5,
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                leadingDistribution: TextLeadingDistribution.even,
                              )))),
                ],
              ),
            ),
            Expanded(
              child: Center(
                child: Container(
                  child: ListView.builder(
                      itemCount: posts == null ? 0 : posts.length,
                      itemBuilder: (context, index) {
                        Post post = posts[index];
                        return Container(
                          decoration: const BoxDecoration(
                            border: Border(
                                bottom: BorderSide(color: Colors.blueAccent)),
                          ),
                          child: ListTile(
                            title: Row(
                              // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: &lt;Widget&gt;[
                                Expanded(child: Center(child: Text(post.date))),
                                Expanded(child: Center(child: Text(post.rate))),
                                Expanded(
                                    child: Center(child: Text(post.koreanwon))),
                                Expanded(child: Center(child: Text(post.dollar))),
                              ],
                            ),
                          ),
                        );
                      }),
                ),
              ),
            ),
          ],
        ),
  
  
      ];
    }
  
    @override
    int _selectedIndex = 0;
  
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(loading ? 'Loading...' : 'Posts'),
        ),
        bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          backgroundColor: Colors.grey,
          selectedItemColor: Colors.white,
          unselectedItemColor: Colors.white.withOpacity(.60),
          selectedFontSize: 14,
          unselectedFontSize: 14,
          currentIndex: _selectedIndex,
          //현재 선택된 Index
          onTap: (int index) {
            setState(() {
              _selectedIndex = index;
            });
          },
          items: &lt;BottomNavigationBarItem&gt;[
            BottomNavigationBarItem(
              title: Text('Favorites'),
              icon: Icon(Icons.favorite),
            ),
            BottomNavigationBarItem(
              title: Text('Music'),
              icon: Icon(Icons.music_note),
            ),
            BottomNavigationBarItem(
              title: Text('Places'),
              icon: Icon(Icons.location_on),
            ),
            BottomNavigationBarItem(
              title: Text('News'),
              icon: Icon(Icons.library_books),
            ),
          ],
        ),
        body: Center(
          child: _widgetOptions.elementAt(_selectedIndex),
        ),
      );
    }
  }
  
  // }
  
  </code></pre>