代码之家  ›  专栏  ›  技术社区  ›  Shady Aziza

使用onTap导航到特定页面

  •  0
  • Shady Aziza  · 技术社区  · 7 年前

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

    单击抽屉项目时出现错误消息 enter image description here

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

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

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

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

    这让人困惑,但我不明白在登录到view Tabs()后如何重定向用户,我的程序的当前流程是: 登录页面()->按下时:_sign->使用Google()调用\u testSignInWithGoogle()->创建新选项卡()。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Collin Jackson    7 年前

    它对我来说很好,所以如果可以的话,请发布一个简化的测试用例。你确定没有其他的吗 Navigator 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(),
      }
      ));
    }
    

    如果你不能找出你的版本和我的版本有什么不同,你可以尝试实现 onGenerateRoute routes 参数到 材料应用