why flutter BottomNavigationBar changes the icon but does not change the page?

Issue

Im new to coding and flutter and I have been trying to make my bottomNavigationBar change pages from home page to chatroom but what ever I try is not working , I watched many videos but their bottomNavigationBar is inside their body and when I apply what they are doing I get the red line under my padding right after body and return Scaffold( right under this parenthesis before my appBar: image link is at the end of the code

     import 'package:flutter/material.dart';
    import 'package:flutter/cupertino.dart';
    import 'package:flutter_rating_bar/flutter_rating_bar.dart';
    import 'package:trading/core/const.dart';
    import 'package:trading/models/apartment_model.dart';
    import 'package:trading/pages/chat.dart';
    import 'package:trading/pages/detail_page.dart';

    class Homepage extends StatefulWidget {
      @override
      _HomepageState createState() => _HomepageState();
    }

    class _HomepageState extends State<Homepage> {
      var data = ApartmentModel.list;

      int _selectedIndex = 0;
       List<Widget> `enter code here`pages=[
       Homepage(),

       Chatroom(),

        ];




      @override
      Widget build(BuildContext context) {
        return Scaffold(


          appBar: AppBar(
            backgroundColor: Colors.transparent,
            elevation: 0,
            title: Text(
              "find your product",
              style: TextStyle(color: Colors.black87, fontWeight: FontWeight.bold),
            ),
            actions: <Widget>[
              IconButton(
                  icon: Icon(
                    Icons.search,
                    color: Colors.black38,
                  ),
                  onPressed: () {}),
              IconButton(
                  icon: Icon(
                    Icons.filter_list,
                    color: Colors.black38,
                  ),
                  onPressed: () {}),
            ],

          ),



bottomNavigationBar: 

   BottomNavigationBar(
      showSelectedLabels: false,
      showUnselectedLabels: false,
      type: BottomNavigationBarType.fixed,
      selectedItemColor: AppColors.stylecolor,
      unselectedItemColor: Colors.black38,
        currentIndex: _selectedIndex,




      items: [
        BottomNavigationBarItem(

            icon: Icon(Icons.home), title: Text("datsa")),
        BottomNavigationBarItem(

            icon: Icon(Icons.chat), title: Text("data"),),
        BottomNavigationBarItem(
            icon: Icon(Icons.person), title: Text("data")),
      ],

      ),


  body: 
     pages.elementAt(_selectedIndex),
  Padding(    
    padding: EdgeInsets.all(16.0),

    child:   

    Column(

      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Text(
          "65 result in your area",
          style: TextStyle(color: Colors.black38),
        ),
        Expanded(
          child: ListView.builder(

            physics: BouncingScrollPhysics(),
            itemCount: data.length,
            itemBuilder: (context, index) {
              return GestureDetector(
                  onTap: () {
                    Navigator.of(context).push(
                      MaterialPageRoute(
                        builder: (_) => DetailPage(
                          data[index]
                        ),
                      ),
                    );
                      },
                      child: _buildItem(context, index));
                },
              ),
            ), 
         //   Container(       child: _builBottomNavigationBar),
          ],

        ),

      ),

    );  
  }

here is a pic of the red line that I was saying

Solution

body can take one widget not more, you assign pages and padding if you want both you must use a column

Answered By – Mohammad_Asef

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *