Flutter Won't Load New List Builder page

Viewed 22

I have been working on this for several hours and I give up. I need help please. I am selecting a BottomNavBarItem onTap and I launch a void function called _onItemTapped which then determines the index of the BNBI then launches a new Class. I have a couple test prints in the code so I can see that it gets down to the second 'print 'testing1'' but nothing loads and nothing happens. Can someone please explain what I am doing wrong?

Code below from the BNBI code

  BottomNavigationBarItem(
          backgroundColor: Colors.blueGrey,
          icon: Icon(Icons.login),
          label: '        Search \n Ingredients Db',
          tooltip:
              'Login or Create an Account to Search Ingredients Database',
        ),
      ],
      
      onTap: _onItemTapped,




   //loads

  void _onItemTapped(final int index) {
    setState(()  {
    Future.sync(() => _CocPageState());
    _selectedIndex = index;
   });
   if (_selectedIndex == 0) {
     _CocPageState()
      .build(context); // takes you to the Chemicals of Concern page.
   } else if (_selectedIndex == 1) {
  _CocPageState().build(context); // //todo go to the dirty list
    } else if (_selectedIndex == 2) {
  _CocPageState().build(context); //todo go to the safer products list
   }
   _CocPageState().build(context);
  }



 // to the Class
class CocPage extends StatefulWidget {
  @override
  _CocPageState createState() => _CocPageState();
}

class _CocPageState extends State<CocPage> {

  @override
 Widget build(BuildContext context) {
    print('test');
    const title =
    'Chemicals of Concern';

  print('testing1');  //nothing happens beyond this point that I can tell.

       return Scaffold(
        body: ListView.builder(
         itemCount: chemBrain.chemsBank.length,
         //     itemBuilder: (context, index),
        prototypeItem: ListTile(
           title: Text('Index 0: chemBrain.chemsBank[index].chemName')),
        itemBuilder: (BuildContext context, index) {
          return ListTile(
           title: Text(chemBrain.chemsBank[index].chemName),
           trailing: Column(
             children: [
            InkWell(
              child: Text(chemBrain.getChemsName()),
1 Answers

I would suggest that you call Navigator.of(context).push() when you tap on the BottomNavigationBarItem.Then you simply push to a new screen and don't have to worry about state.

Related