每当我尝试通过单击抽屉中的图标进行导航时,都会收到此错误
...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 身份验证一起使用,但我需要在登录后重定向用户以查看我的应用程序。
我是新手,所以我仍然不知道如何解决这个问题,所以我在这里做了什么
Future<String> _testSignInWithGoogle() async{
//implement signin
runApp(
new MaterialApp(
home: new Tabs(),
)
);
return 'signInWithGoogle succeeded: $user';
}
这令人困惑,但我不明白在登录后如何重定向用户以查看 Tabs(),我的程序的当前流程是: loginPage()->onPressed: _signIn -> 调用 _testSignInWithGoogle()-> created新标签()。
它对我来说很好用,所以如果可以的话,请发布一个简化的测试用例。您确定您的代码中没有任何其他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
参数传递给MaterialApp
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句