使用 onTap 导航到特定页面

Using onTap to navigate to a specific page

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

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

...onTap:_profile
//jump to function...
Widget build (BuildContext context){
void _profile() {
  Navigator.popAndPushNamed(context, "/Profile");}...

这是主要功能的样子

    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(),.....

更新:

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

我是 flutter 的新手,所以我仍然不知道如何解决这个问题所以这里是我所做的

Future<String> _testSignInWithGoogle() async{
//implement signin
runApp(
  new MaterialApp(
    home: new Tabs(),
  )
);
 return 'signInWithGoogle succeeded: $user';
}

这很混乱,但我不明白在登录后如何重定向用户以查看 Tabs(),我程序的当前流程是: loginPage()->onPressed: _signIn -> 调用 _testSignInWithGoogle()-> 创建新的 Tabs()。

它对我来说工作得很好,所以如果可以的话,请 post 简化测试用例。您确定您的代码中没有任何其他 NavigatorMaterialApp 实例吗?

这是我用来测试的代码。

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

如果你无法弄清楚你的版本和我的版本有什么不同,你可以尝试实现 onGenerateRoute 而不是将 routes 参数传递给 MaterialApp