Flutter 无法使底部导航栏和布线在颤振中一起工作

Flutter 无法使底部导航栏和布线在颤振中一起工作,flutter,routes,navigation,Flutter,Routes,Navigation,我是一个新手,无法从底部导航栏导航到新页面 我有一个主应用程序 class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( statusBarColor: Colors.

我是一个新手,无法从底部导航栏导航到新页面

我有一个主应用程序

    class MyApp extends StatelessWidget {
          @override
           Widget build(BuildContext context) {
            SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
              statusBarColor: Colors.transparent,
            ));
            return MaterialApp(
              title: 'Flutter Demo',
              theme: ThemeData(primarySwatch: Colors.blue),
              builder: (BuildContext buildContext, Widget widtget) => Scaffold(
                body: RootNavigator(),
                bottomNavigationBar: BottomNavigation(),
              ),
            );
          }
        }
和根导航器

    class RootNavigator extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Navigator(
          initialRoute: '/',
          onGenerateRoute: (RouteSettings settings) {
            // final args = settings.arguments;

            return MaterialPageRoute(
                settings: settings,
                builder: (BuildContext context) {
                  switch (settings.name) {
                    case '/':
                      return Page1();
                    case '/page2':
                      return Page2();
                    case '/page3':
                      return Page3();
                    default:
                      return RouteErrorPage();
                  }
                });
              },
            );
          }
    }
class BottomNavigation extends StatefulWidget {
  @override
  BottomNavigationState createState() {
    return new BottomNavigationState();
  }
}

class BottomNavigationState extends State<BottomNavigation> {
  int currIndex = 0;

  onTap(int index) {
    setState(() => currIndex = index);
    switch (index) {
      case 0:
        Navigator.pushNamed(context, '/');
        break;
      case 1:
        Navigator.pushNamed(context, '/page2');
        break;
      case 2:
        Navigator.pushNamed(context, 'page3');
        break;
      default:
        Navigator.push(
            context, MaterialPageRoute(builder: (_) => RouteErrorPage()));
    }
  }
   ....
  // added app bar items
}
和底部导航仪

class BottomNavigation extends StatefulWidget {
  @override
  BottomNavigationState createState() {
    return new BottomNavigationState();
  }
}

class BottomNavigationState extends State<BottomNavigation> {
  int currIndex = 0;

  onTap(int index) {
    setState(() => currIndex = index);
    switch (index) {
      case 0:
        Navigator.pushNamed(context, '/');
        break;
      case 1:
        Navigator.pushNamed(context, '/page2');
        break;
      case 2:
        Navigator.pushNamed(context, 'page3');
        break;
      default:
        Navigator.push(
            context, MaterialPageRoute(builder: (_) => RouteErrorPage()));
    }
  }
   ....
  // added app bar items
}
class BottomNavigation扩展了StatefulWidget{
@凌驾
BottomNavigationState createState(){
返回新的BottomNavigationState();
}
}
类BottomNavigationState扩展状态{
int currIndex=0;
onTap(整数索引){
设置状态(()=>currendex=index);
开关(索引){
案例0:
Navigator.pushNamed(上下文“/”);
打破
案例1:
Navigator.pushNamed(上下文“/page2”);
打破
案例2:
pushNamed(上下文“page3”);
打破
违约:
导航器。推(
上下文,MaterialPartnerRoute(生成器:()=>RouteErrorPage());
}
}
....
//添加了应用程序栏项目
}
选项卡正在切换,但路由未切换。它会留在主页上。 我觉得有些事情是有背景的,但不知道如何解决它。 有人能帮忙吗? 谢谢


p、 如果我将底部导航栏分别移动到每个页面上,所有内容都可以正常工作,除了选中的选项卡(因为状态),我还想保留一个,共享应用程序栏回答是-@LoVe comment是正确的。 这就是颤振的工作原理。 如果你有底部导航,你必须浏览页面。 重定向意味着移动到全新的页面,在那里您必须从sratch定义Scaffold。
如果你想共享AppBar-使其可重用小部件

答案是-@LoVe comment是正确的。 这就是颤振的工作原理。 如果你有底部导航,你必须浏览页面。 重定向意味着移动到全新的页面,在那里您必须从sratch定义Scaffold。
如果您想要共享AppBar-使其可重复使用小部件

,那么当用户单击底部栏中的图标时,您需要滑动页面?如果是,请查看
页面视图
hmm yyes我想导航到bootm导航栏上的其他页面项目单击。如果我正确理解PageView,它属于一个功能(帐户有不同的选项卡)。然而,底部的标签是不同的功能,如帐户、搜索等。我认为这里的路由更合适(可能我弄错了,不知道什么时候使用pageView,什么时候使用路由)?但我的问题仍然存在——为什么当我在mainApp中有bottomnavigation时导航不起作用,而当我在单独的页面中有bottomNavBar时导航却起作用。你找到解决方案了吗?是的,你能把它贴在回答中吗?See:那么当用户点击底部栏中的图标时,你需要滑动页面吗?如果是,请查看
PageView
hmm-yyes我想导航到bootm导航栏上的另一个页面项目单击。如果我正确理解PageView,它属于一个功能(帐户有不同的选项卡)。然而,底部的标签是不同的功能,如帐户、搜索等。我认为这里的路由更合适(可能我弄错了,不知道什么时候使用pageView,什么时候使用路由)?但我的问题仍然存在——为什么当我在mainApp中有bottomnavigation时导航不起作用,而当我在单独的页面中有bottomNavBar时导航却起作用。你找到解决方案了吗?是的,你能把它贴在这里吗