Flutter 底部导航栏

时间:2021-07-20 02:08:44

标签: flutter bottomnavigationview pagecontrol

我制作了一个运行良好的底部导航栏。

  1. 但我不知道如何让它显示在底部导航栏之外的页面上。
  2. 当我热重启时,底部导航器消失了,如何解决。

这是导航栏的代码:

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {


  PageController _pageController = PageController();
  List<Widget> _screen = [
    Home(),
    MyProfile(),
    Conversations(),
    SearchPage()
  ];
  void _onPageChanged(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  void _onItemTapped(int selectedIndex) {
    _pageController.jumpToPage(selectedIndex);
  }


  int _selectedIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _pageController,
        children: _screen,
        onPageChanged: _onPageChanged,
        physics: NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._selectedIndex,
        selectedItemColor: Colors.green,
        unselectedItemColor: Colors.black45,
        backgroundColor: Colors.black,
        selectedLabelStyle: TextStyle(fontWeight: FontWeight.bold),
        onTap: _onItemTapped,
        items: [
          BottomNavigationBarItem(
            icon: Icon(
              Icons.home,
            ),
            label: 'Home',
          ),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.person,
              ),
              label: 'Profile'),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.sms,
              ),
              label: 'Messages'),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.search,
              ),
              label: 'Search'),
        ],
      ),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

我点击此链接 enter link description here

并且底部导航器现在显示在所有页面中。 但它仍然随着热重启而消失。此外,当我关闭应用程序并重新打开时,并且在热重启后无法导航到其他页面。

这是我犯的一个愚蠢的错误。我忘记将已登录用户的主页更改为主页。