Flutter 颤振:带底部栏菜单的导航架构

Flutter 颤振:带底部栏菜单的导航架构,flutter,Flutter,我仍然没有完全掌握颤振中的构建和导航过程,我想知道如何设计一个包含许多页面的更复杂应用程序的主导航架构 在我的例子中,我有一个带有脚手架的主页,一个用于导航的底部栏和其中的5个项目 class _HomePageState extends State<HomePage> { int _selectedIndex = 0; @override Widget build(BuildContext context) { return Scaffold( a

我仍然没有完全掌握颤振中的构建和导航过程,我想知道如何设计一个包含许多页面的更复杂应用程序的主导航架构

在我的例子中,我有一个带有脚手架的主页,一个用于导航的底部栏和其中的5个项目

class _HomePageState extends State<HomePage> {
  int _selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(...),
      body: [Page1(), Page2(), Page3(), Page4(), Page5()].elementAt(_selectedIndex),
      bottomNavigationBar: BottomAppBar(
          child: Row(
            children: [
              IconButton(
                icon: Icon(
                  FeatherIcons.home,
                  size: 27,
                  color: (_selectedIndex == 0)
                      ? Colors.yellow[600]
                      : Colors.grey[800],
                ),
                onPressed: () {
                    setState(() {
                      _selectedIndex = 0;
                    });
                },
              ),
            // four more Icon Buttons ....
           ]
          ),
         ),
   );
其中,
AppBar.title
中有两个图标按钮用于更改索引


这些是导航方面的糟糕做法吗?我应该为主页中的5个主页使用页面视图,还是处理导航的最佳方式?

我建议您为第2页创建一个页面,并通过使用颤振选项卡使用颤振选项卡,您不必执行此检查**(\u index=0)?TabPage1():TabPage2(),**您可以访问页面2内的两个选项卡页面。为了清晰和可维护性,最好使用Flatter中提供的导航功能。我绝对建议在您提供的示例中使用
PageView
以及
TabBar
Scaffold(
   ...
   body: (_index = 0) ? TabPage1() : TabPage2(),
)