title: how to use bottomNavigationBar while using ListView.builder
body: <p>I want to use bottomNavigationBar with listview, I tried each one of them separately and they work fine, but when I use them together, the bottomNavigationBar doesn't work, you can press the icons but nothing happens.</p>
  <p>note: I'm using an older version of dart to avoid null-safety which is dumb, but the reason is the book I read is from 2019 so I couldn't follow without using an older version.</p>
  <p>note 2: I'm very new to programming.</p>
  <p>main.dart</p>
  <pre><code>    //@dart=2.9
  import 'package:flutter/material.dart';
  import 'package:ch8_bottom_navigation/pages/home.dart';
  
  void main() =&gt; runApp(Myapp());
  
  class Myapp extends StatelessWidget {
    //this widget is the root of the app
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Starter Template',
        theme: ThemeData  (
          primarySwatch: Colors.blue,
          platform: TargetPlatform.iOS,
  
        ),
        home: Home(),
      );
  
    }
  
  }
  </code></pre>
  <p>home.dart</p>
  <pre><code>   //@dart=2.9
  import 'package:flutter/material.dart';
  import 'discover.dart';
  import 'home2.dart';
  import 'account.dart';
  
  
  
  class Home extends StatefulWidget {
    const Home({Key key}) : super(key: key);
  
    @override
    _HomeState createState() =&gt; _HomeState();
  }
  
  class _HomeState extends State&lt;Home&gt; {
  
    int _currentIndex = 0;
    List _listPages = [];
    Widget _currentPage;
    @override
    void initState() {
      super.initState();
  
      _listPages
      ..add(Home2())
      ..add(Discover())
      ..add(Account());
      _currentPage = Discover();
    }
    void _changePage(int selectedIndex) {
      setState(() {
        _currentIndex = selectedIndex;
        _currentPage = _listPages[selectedIndex];
      });
  
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: SafeArea(
          child: ListView.builder(
            itemCount:20 ,
            itemBuilder: (BuildContext context , int index) {
              if (index &gt;= 0 &amp;&amp; index &lt;= 0) {
                return Home2 (index:index);
              }
              else return null;
            },
          ),
        ),
          bottomNavigationBar: BottomNavigationBar(
            currentIndex: _currentIndex,
            items: [
              BottomNavigationBarItem(
                  icon: Icon(Icons.live_tv),
                  label: ('Home'),
              ),
              BottomNavigationBarItem(
                  icon: Icon(Icons.explore_outlined),
                label: ('Discover'),
              ),
              BottomNavigationBarItem(
                  icon: Icon(Icons.account_box_outlined),
                label: ('Account'),
              ),
            ],
            onTap: (selectedIndex) =&gt; _changePage(selectedIndex),
          ),
  
  
  
      );
  
    }
  }
  </code></pre>
  <p>home2.dart</p>
  <pre><code>//@dart=2.9
  import 'package:flutter/material.dart';
  
  class Home2 extends StatelessWidget {
    const Home2({Key key , @required this.index}) : super(key: key);
    final int index;
    @override
    Widget build(BuildContext context) {
      return Container(
          child:Card(
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(12),
            ),
            color: Colors.white70,
            child: ListTile(
              leading: Image(
                image: AssetImage('assets/images/blackwidow.jpg'),
              ),
              title: Text('Black Widow'),
              subtitle: Text('By Disney'),
              trailing: Icon(Icons.movie),
              selected: true,
              onTap: () {
                print('Trapped on Row $index');
              },
            ),
          )
      );
  
    }
  }
  </code></pre>