我正在尝试使用共享首选项保持会话或登录,但在模拟器中,当我进行热重启或重新加载时,它工作正常。 当我关闭物理设备上的应用程序或使用另一个应用程序时会出现问题,因为它无法验证,因此如果您已登录,则会出现相应的屏幕。
En dipositivo fisico se queda en la pantalla login.
这是代码
// flutter
class Frm_Login extends State<frm_Login>{
var islogin = null;
Future<void> CheckLoginUusuario() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
islogin = prefs.getBool("CheckEstadoLogin");
}
@override
void initState() {
CheckLoginUusuario();
super.initState();
}
@override
Widget build(BuildContext context) {
return islogin == true ? MenuPrincipal():
LoginPage(
child: new TextButton(
onPressed: (){
if(KeyFormValidaciones.currentState.validate()){
validarLoginservices.ValidarLogin(Contrasena.text,Usuario.text , context);
}
},
child: new Text("Login",style: new TextStyle(fontSize: 25,color: Colors.white),),
)
);
}
class ValidarLoginServices {
SharedPreferences prefs = await SharedPreferences.getInstance();
Future ValidateLogin(ContrasenaLogin,CorreoLogin,BuildContext context) async {
if(// if validate password and email is ok ){
await prefs.setBool("CheckEstadoLogin", true);
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context)=>MenuPrincipal()), (route) => false);
}}}