flutter - Flutter:登录后重定向到原点
问题描述
需要一些有关如何路由到新页面然后返回到原始呼叫者的帮助..
在我的应用程序中,主页是项目列表。当用户选择一个项目时,他们会看到带有更多信息按钮的详细信息...在某些项目上,用户需要登录才能查看更多数据。
因此,在上述情况下,我有到登录页面的路由,在他们登录后,我需要重定向回相同的记录详细信息页面。
我怎么能在颤动中做到这一点。
如果选择更多信息,这是我用户将他们引导到登录屏幕的代码
Navigator.of(context, rootNavigator: true)
.push(CupertinoPageRoute<void>(
title: "login",
builder: (BuildContext context) => LoginScreen(),
),
);
- - 更新 -
这是我对登录屏幕的调用,但“isLoginSuccess”的返回值始终为空
_navigateToLogin(applyType) async {
Future<bool> isLoginSuccess = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginScreen(),
),
);
isLoginSuccess.then((onValue) {
if (onValue) {
_navigateToResumeScreen(applyType);
}
});
}
用户登录后..这是返回初始屏幕的弹出命令
Navigator.of(context).pop(true);
价值为
谢谢你的帮助
解决方案
有很多方法可以做到,这取决于您的登录流程如何工作,这是最简单的方法,
class LoginScreen extends StatefulWidget {
@override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
children: <Widget>[
RaisedButton(
child: Text('Login'),
onPressed: login,
),
],
)
),
);
}
void login() {
// simulate the login
Future.delayed(Duration(seconds: 2)).then((_){
setState(() {
// update the UI ,
});
// navigate to previous route
Navigator.of(context).pop('pass some result back to previus screen');
// while you pushed to this screen you can a wait the result
// coming from this screen
// for more info see the navigation in flutter in general
});
}
}
推荐阅读
- git - Git - 如何压缩选定的提交?
- python - 如何退出调用 django 服务器的子进程?
- c++ - 游戏对象向左和向上移动,但不向右和向下移动
- .net-core - net core 2.2 本地自定义用户帐号 System.InvalidOperationException
- ios - UITextView 不显示
- python - Flask BluePrint 路由不适用于多个参数
- python - 如何通过 .py 文件上的 id 修改 kivy 小部件属性
- python - 将字典列表与逻辑和操作进行比较
- css - 如何设置子菜单背景颜色的样式?
- xml - 从多个导入的 XSLT 中选择应用