Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在flatter中,如何处理密码屏幕';s广播旗_Flutter_Broadcast - Fatal编程技术网

Flutter 在flatter中,如何处理密码屏幕';s广播旗

Flutter 在flatter中,如何处理密码屏幕';s广播旗,flutter,broadcast,Flutter,Broadcast,我已经使用上的示例实现了我的屏幕锁定实用程序版本,但不确定当用户输入正确的密码时,如何使用my main.dart中的“\u verificationNotifier”路由到我的主页。这是我的主飞镖 class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return

我已经使用上的示例实现了我的屏幕锁定实用程序版本,但不确定当用户输入正确的密码时,如何使用my main.dart中的“\u verificationNotifier”路由到我的主页。这是我的主飞镖

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'MyAppTitle',
      // home: SheetScreen(),
      home: LoginPage(),
    );
  }
}
登录页面几乎就是示例中的内容。现在我正在求助于

if (isValid) {
        setState(() {
          this.isAuthenticated = isValid;
        });
        Navigator.pushReplacement(context,
            MaterialPageRoute(builder: (BuildContext ctx) => SheetScreen()));

我不认为这是正确的,带有广播的StreamController的目的似乎是必须“收听”并适当路由。有人能帮你举个例子吗?

我想你不需要streamcontroller

在我管理它的方式中,我显示我的登录页面,当用户放入他们的凭据并按下按钮时,调用我的控制器,该控制器将调用后端来验证凭据。如果由于我的用例而成功,我将它保存在一个安全的存储中,以便用户始终被锁定,但您可以跳过此操作。然后将值返回到登录页面并按下新屏幕。看

void _login(context) async {
    String successLogin;
    if (_loginFormKey.currentState!.validate()) {
      successLogin =
          await login(emailInput.getValue(), passwordInput.getValue());

      if (successLogin != ERROR101 && successLogin == LOGGED) {

        Navigator.of(context).pushNamedAndRemoveUntil(
            HomePage.routeName, (Route<dynamic> route) => false);
      } else {
        showDialog(
            context: context,
            builder: (context) => ErrorAlert(
                title: AppLocalizations.of(context)!.errorOccurred,
                message: AppLocalizations.of(context)!.noAccountFound));
      }
    }
void\u登录(上下文)异步{
字符串成功登录;
如果(\u loginFormKey.currentState!.validate()){
成功登录=
等待登录(emailInput.getValue(),passwordInput.getValue());
if(successLogin!=ERROR101&&successLogin==LOGGED){
Navigator.of(context.pushName和removeUntil)(
HomePage.routeName,(路由)=>false);
}否则{
显示对话框(
上下文:上下文,
生成器:(上下文)=>ErrorAlert(
标题:AppLocalizations.of(上下文)!。发生错误,
消息:AppLocalizations.of(context)!.noAccountFound));
}
}
我的控制器:

Future<String> login(email, password) async {
  final response = await http.post(Uri.parse('$_baseUrl/auth/local'),
      body: {"identifier": email, "password": password});

  if (response.statusCode == 200) {
    dynamic body = jsonDecode(response.body);
    String jwt = body['jwt'];
    int userId = body['user']['id'];
    USERNAME = body['user']['firstName'];

    if (jwt != null) {
      await writeJWT(jwt);
      await writeUserStore(email);
      await writeUserId(userId);
      await writePassword(password);
      await writeRole(body['user']['role']['name']);
      USERLOGGED = true;
      return LOGGED;
    } else {
      return ERROR101;
    }
  } else {
    return ERROR101;
  }
}
未来登录(电子邮件、密码)异步{
final response=wait http.post(Uri.parse(“$\u baseUrl/auth/local”),
正文:{“标识符”:电子邮件,“密码”:密码});
如果(response.statusCode==200){
动态body=jsonDecode(response.body);
字符串jwt=body['jwt'];
int userId=body['user']['id'];
用户名=正文['user']['firstName'];
如果(jwt!=null){
等待书面通知(jwt);
等待writeUserStore(电子邮件);
等待writeUserId(用户ID);
等待写入密码(密码);
等待writeRole(body['user']['role']['name']);
USERLOGGED=true;
返回记录;
}否则{
返回错误101;
}
}否则{
返回错误101;
}
}

正如您所见,我将一些用户信息保存在内存中供以后使用。

我见过使用SharedReferences(localStorage)来处理登录的示例。您也在做类似的事情。但我假设插件的作者出于某种原因将其放入带有广播的StreamController中。我认为它是main.dart中使用的某种钩子