扑动BottomNavigationBar更改图标,但不更改页面

时间:2020-05-21 19:16:35

标签: flutter bottomnavigationview flutter-navigation flutter-appbar flutter-bottomnavigation

我对编码和抖动并不陌生,我一直在尝试将bottomNavigationBar的页面从home page更改为chatroom,但是我尝试的所有方法都不起作用,我看了很多视频,但是他们的bottomNavigationBar在他们的身体内部,当我应用他们的工作时,我在padding下面的红线紧随身体,而在return Scaffold(下的红色括号内则在我的appBar:之前图像链接位于代码的结尾

     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

2 个答案:

答案 0 :(得分:0)

您必须制作一个包含页面的Widgets列表,并在body中根据Widget填充Selected Index

示例:

List<Widget> pages=[
  Dashboard(),
  Profile(),
  Settings(),
];

然后将页面在正文中显示为:

body:
   pages.elementAt(_selectedIndex),

答案 1 :(得分:0)

body只能容纳一个小部件,如果您要同时使用两列,则可以分配页面和填充