【问题标题】:Flutter bottom navigator BarFlutter 底部导航栏
【发布时间】:2021-07-20 02:08:44
【问题描述】:

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

  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'),
        ],
      ),
    );
  }
}

【问题讨论】:

  • 您的代码工作正常,但您的问题是什么
  • 我有其他页面不在底部导航栏中。 (我可以把它们放在那里,因为我希望这些用户提供一些数据)。如何在这些页面上显示底部导航器?另外,当我热重启时,底部导航器消失了。如何解决?

标签: flutter bottomnavigationview pagecontrol


【解决方案1】:

我点击这个链接enter link description here

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-07
    • 2022-01-18
    • 2020-07-30
    • 2021-06-27
    • 2021-01-01
    • 1970-01-01
    • 2018-10-04
    相关资源
    最近更新 更多