0

我是编码和颤动的新手,我一直在尝试将我的bottomNavigationBar页面从home pageto更改为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),
          ],

        ),

      ),

    );  
  }

这是我说的红线的图片

4

2 回答 2

0

body 不能再占用一个小部件,如果需要,您可以分配页面和填充,您必须使用一列

于 2020-05-22T01:07:08.497 回答
0

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

例子:

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

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

body:
   pages.elementAt(_selectedIndex),
于 2020-05-21T19:20:57.123 回答