【问题标题】:Navigating to another screen without bottomNavigationBar Icons in flutter but keeping the bottomNavigationBar in anotherScreen导航到没有bottomNavigationBar图标的另一个屏幕颤动但将bottomNavigationBar保留在anotherScreen
【发布时间】:2020-09-02 10:12:05
【问题描述】:

我有一个main.dart,底部导航栏有 5 个标签,当点击标签时,它会转到相应的页面。

void main() => runApp(MyStatefulWidget());

class MyStatefulWidget extends StatefulWidget {
  @override
  _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  int _selectedIndex = 0;

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  final List<Widget> _children = [
    ProfilePage1(),
    EventPage3(),
    HomePage2(),
    AllEventPage(),
    ProfilePage1(),
  ];

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider<EventModifier>(
            create: (context) => EventModifier()),
      ],
      child: MaterialApp(
        debugShowCheckedModeBanner: false,

        home: Scaffold(
          body: Center(child: _children.elementAt(_selectedIndex)),
          bottomNavigationBar: BottomNavigationBar(
            items: <BottomNavigationBarItem>[
              BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("")),
              BottomNavigationBarItem(
                  icon: Icon(Icons.calendar_today), title: Text("")),
              BottomNavigationBarItem(
                  icon: Icon(
                    Icons.account_circle,
                    size: 45,
                    color: Color(0xFF334192),
                  ),
                  title: Text("")),
              BottomNavigationBarItem(
                  icon: Icon(Icons.message), title: Text("")),
              BottomNavigationBarItem(
                  icon: Icon(Icons.table_chart), title: Text("")),
            ],
            currentIndex: _selectedIndex,
            selectedItemColor: Color(0xFF334192),
            unselectedItemColor: Colors.grey,
            onTap: _onItemTapped,
          ),
        ),
      ),
    );
  }
}

现在,在第 3 个选项卡中有一个名为“查看全部”的按钮,单击它应该转到第 4 页带有底部导航栏,并自动单击底部导航栏的第 4 个选项卡。
如何在颤振中做到这一点?颤振

【问题讨论】:

  • 我希望我的回答能回答你的问题。如果它有用,请花点时间接受并投票。否则,请让我知道您需要澄清什么

标签: flutter bottomnavigationview


【解决方案1】:

要手动更改bottomNavigationBar选定的项目,您需要设置

_selectedIndex = 4;   

单击“查看全部”按钮时导航到 AllEventTab...一种方法是在按钮的 onPressed() 中使用 Navigator.push(),如下所示:

onPressed: () {
  Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => AllEventTab()),
  );
}   

“Navigation Basics”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-24
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2020-05-24
    • 2020-10-11
    • 1970-01-01
    相关资源
    最近更新 更多