Dart 使用onTap导航到特定页面

Dart 使用onTap导航到特定页面,dart,flutter,Dart,Flutter,每当我试图通过单击抽屉中的图标来导航时,我都会收到此错误 单击抽屉项目时出现错误消息 这就是主函数的外观 void main() { runApp(new MaterialApp( home: new LoginPage(), routes: <String, WidgetBuilder>{ "/Feed": (BuildContext context) => new first.Feed(), "/Settings":(BuildC

每当我试图通过单击抽屉中的图标来导航时,我都会收到此错误

单击抽屉项目时出现错误消息

这就是主函数的外观

    void main() {
  runApp(new MaterialApp(
    home: new LoginPage(),

  routes: <String, WidgetBuilder>{
    "/Feed": (BuildContext context) => new first.Feed(),
    "/Settings":(BuildContext context) => new sixth.Settings(),
    "/Profile": (BuildContext context) => new fifth.Profile(),
    "/Search": (BuildContext context) => new second.Search(),
    //"/Signout":(BuildContext context) => new LogoutPage(),
    "/Notify": (BuildContext context) => new third.Notifications(),
    "/Feedback": (BuildContext context) => new fourth.Feedback(),
    "/Tabs": (BuildContext context) => new Tabs(),.....
void main(){
runApp(新材料)PP(
主页:新登录页(),
路线:{
“/Feed”:(BuildContext上下文)=>newfirst.Feed(),
“/Settings”:(BuildContext)=>new sixth.Settings(),
“/Profile”:(BuildContext)=>new fifth.Profile(),
“/Search”:(BuildContext上下文)=>new second.Search(),
//“/Signout”:(BuildContext上下文)=>new LogoutPage(),
“/Notify”:(BuildContext上下文)=>new third.Notifications(),
“/Feedback”:(BuildContext上下文)=>new fourth.Feedback(),
“/Tabs”:(构建上下文)=>newtabs(),。。。。。
更新:

我正在使用带有firebase身份验证的google sigin,但我需要在登录后重定向用户以查看我的应用程序

我是新手,所以我仍然不知道如何解决这个问题,所以我在这里做了什么

Future<String> _testSignInWithGoogle() async{
//implement signin
runApp(
  new MaterialApp(
    home: new Tabs(),
  )
);
 return 'signInWithGoogle succeeded: $user';
}
Future\u testSignInWithGoogle()异步{
//执行符号
runApp(
新材料聚丙烯(
主页:新选项卡(),
)
);
返回'signInWithGoogle successed:$user';
}
这令人困惑,但我不明白在登录到view Tabs()后如何重定向用户,我的程序的当前流程是:
loginPage()->onPressed:_signIn->calls _testSignInWithGoogle()->创建新选项卡()。

它对我来说很好,所以如果可以,请发布一个简化的测试用例。您确定代码中没有任何其他
导航器
MaterialApp
实例吗

下面是我用来测试的代码

import 'package:flutter/material.dart';

class LoginPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    void _profile() {
      Navigator.popAndPushNamed(context, "/Profile");
    }
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Login'),
      ),
      drawer: new Drawer(
        child: new InkWell(
          onTap: _profile,
          child: new Icon(Icons.navigate_next),
        ),
      )
    );
  }
}

class Profile extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new Text('You made it!'),
      ),
    );
  }
}

void main() {
  runApp(new MaterialApp(
    home: new LoginPage(),

  routes: <String, WidgetBuilder>
  {
  "/Profile": (BuildContext context) => new Profile(),
  }
  ));
}
导入“包装:颤振/材料.省道”;
类LoginPage扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
void_profile(){
Navigator.popandpushname(上下文,“/Profile”);
}
归还新脚手架(
appBar:新的appBar(
标题:新文本(“登录”),
),
抽屉:新抽屉(
孩子:新墨水井(
onTap:_配置文件,
子项:新图标(图标。导航到下一步),
),
)
);
}
}
类配置文件扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
归还新脚手架(
正文:新中心(
孩子:新的文本(“你成功了!”),
),
);
}
}
void main(){
runApp(新材料)PP(
主页:新登录页(),
路线:
{
“/Profile”:(BuildContext)=>new Profile(),
}
));
}

如果你不能找出你的版本和我的版本有什么不同,你可以尝试实现
onGenerateRoute
,而不是将
routes
参数传递给
MaterialApp

你能包括对new MaterialApp的调用吗,这样我们就可以看到你的路由是如何设置的?@Collin Jackson我已经将主函数添加到帖子。我想你指出了问题所在,是的,除了主函数中包含的MaterialApp()实例之外,我还有另一个MaterialApp()实例。我已经相应地更新了帖子。哦,我发现我没有在_testSignInWithGoogle()中的MaterialApp()中设置路由方法!非常感谢你的帮助。我可以问你是否发现我的结构在逻辑上是正确的?@ CollinJacksonWhat你做的很好,我通常试着避免不止一次调用<代码> RunApp,因为多个<代码>材质App/<代码>使程序变得更难推理。返回登录页面的一种方法。将尝试此方法,再次感谢您的有用反馈。
import 'package:flutter/material.dart';

class LoginPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    void _profile() {
      Navigator.popAndPushNamed(context, "/Profile");
    }
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Login'),
      ),
      drawer: new Drawer(
        child: new InkWell(
          onTap: _profile,
          child: new Icon(Icons.navigate_next),
        ),
      )
    );
  }
}

class Profile extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new Text('You made it!'),
      ),
    );
  }
}

void main() {
  runApp(new MaterialApp(
    home: new LoginPage(),

  routes: <String, WidgetBuilder>
  {
  "/Profile": (BuildContext context) => new Profile(),
  }
  ));
}