我想在登出时设置导航(忘记密码,注册/登录)与登录时相比(家庭,注销,很多东西)。
我完全不知道如何做到这一点。我看到的所有建议都退出了系统的一部分,一个页面显示登录,但这在这里不起作用。如果我共享导航,那么应用程序其余部分的每个页面都需要登录检查,这听起来有点恼火。是否有一种简单的方法来换出导航设置?可以根据用户登录/退出状态动态添加导航?
我可以将导航类本身子类化并以这种方式处理它吗?
在本地反应中,您可以通过更换登录的导航器和登录的导航器之间的导航器来实现此目的。寻找与此类似的结果。
答案 0 :(得分:1)
React-Native允许嵌套导航器,但颤动不会。虽然没有嵌套任何导航器,但有多种方法可以做到这一点,下面显示了如何使用颤振来完成它的简单示例。
示例:
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
// Main Application
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Example',
// Routes
routes: <String, WidgetBuilder>{
'/': (_) => new Login(), // Login Page
'/home': (_) => new Home(), // Home Page
'/signUp': (_) => new SignUp(), // The SignUp page
'/forgotPassword': (_) => new ForgotPwd(), // Forgot Password Page
'/screen1':(_) => new Screen1(), // Any View to be navigated from home
},
);
}
}
// The login page
class Login extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text("Login Page"),
// The button on pressed, logs-in the user to and shows Home Page
new FlatButton(
onPressed: () =>
Navigator.of(context).pushReplacementNamed("/home"),
child: new Text("Login")),
// Takes user to sign up page
new FlatButton(
onPressed: () => Navigator.of(context).pushNamed("/signUp"),
child: new Text("SignUp")),
// Takes user to forgot password page
new FlatButton(
onPressed: () =>
Navigator.of(context).pushNamed("/forgotPassword"),
child: new Text("Forgot Password")),
],
),
),
);
}
}
// Home page
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text("Home Page"),
// Logs out user instantly from home
new FlatButton(
onPressed: () => Navigator.of(context).pushReplacementNamed("/"),
child: new Text("Logout")),
// Takes user to Screen1
new FlatButton(
onPressed: () => Navigator.of(context).pushNamed("/screen1"),
child: new Text("Screen 1")),
],
),
),
);
}
}
// Sign Up Page
class SignUp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text("Sign Up Page"),
// To make an api call with SignUp data and take back user to Login Page
new FlatButton(
onPressed: () {
//api call to sign up the user or whatever
Navigator.of(context).pop();
},
child: new Text("SignUp")),
],
),
),
);
}
}
// Forgot Password page
class ForgotPwd extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text("Sign Up"),
// Make api call to resend password and take user back to Login Page
new FlatButton(
onPressed: () {
//api call to reset password or whatever
Navigator.of(context).pop();
},
child: new Text("Resend Passcode")),
],
),
),
);
}
}
// Any Screen
class Screen1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text("Screen 1"),
// Takes the user to the view from which the user had navigated to this view
new FlatButton(
onPressed: () => Navigator.of(context).pop(),
child: new Text("Back")),
// Takes back the user to Home page and Logs out the user
new FlatButton(
onPressed: () async {
Navigator.of(context).popUntil(ModalRoute.withName("/home")); // Use popUntill if you want to reset all routes untill now and completely logout user
Navigator.of(context).pushReplacementNamed("/");
// Just to show login page and resume back after login
// Navigator.of(context).pushNamed('/Login');
// On login page after successful login Navigator.of(context).pop();
// the app will resume with its last route.
},
child: new Text("Logout")),
],
),
),
);
}
}
注意:我不是说这是最好的方法,但是这个例子显示了一种简单的方法。
希望有所帮助!
答案 1 :(得分:0)
您可以做到
// this.$refs.CanvasViewRef returns Vue object
// this.$refs.CanvasViewRef.nativeView returns the actual Placeholder
const nativeView = this.$refs.CanvasViewRef.nativeView.nativeView;
...
...
nativeView.setImageBitmap(bitmap);
此处的详细说明https://medium.com/@anilcan/how-to-use-dynamic-home-page-in-flutter-83080da07012