【问题标题】:snapshot connectionstate is always waiting while using stream as FirebaseAuth.instance.onAuthStateChanged使用流作为 FirebaseAuth.instance.onAuthStateChanged 时,快照连接状态始终处于等待状态
【发布时间】:2019-07-22 18:58:03
【问题描述】:

我正在尝试使用 firebase_auth 使用电子邮件和密码创建身份验证代码有 3 页 1.Main 页面检查连接是否已建立或用户是否已登录。并导航到由函数 _handleWidnowDisplay() 完成的相应页面。

但由于某种原因,该应用程序卡在 if (snapshot.connectionState == ConnectionState.waiting){} 块中并且无法连接到 firebase 。

在添加 firebase 依赖项时,我遇到了一些问题,通过将 android.useAndroidX=trueandroid.enableJetifier=true 添加到 gradel.properties 解决了这些问题。

import 'package:flutter/material.dart';
import 'screens/MyLogin.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'screens/MainPage.dart';

void main() => runApp(new MaterialApp(
      color: Colors.red,
      home: _handleWidnowDisplay(),
    ));

Widget _handleWidnowDisplay() {
  return StreamBuilder(
    stream: FirebaseAuth.instance.onAuthStateChanged,
    builder: (BuildContext context, snapshot) {
      if (snapshot.connectionState == ConnectionState.waiting) {
        return Scaffold(
            appBar: AppBar(
              title: new Text("MyLogin"),
              backgroundColor: Colors.red.shade900,
            ),
            body: new Container(
                width: MediaQuery.of(context).size.width,
                height: MediaQuery.of(context).size.height,
                color: Colors.red.shade900,
                child: new Center(
                  child: new Text("Loding....."),
                )));
      } else if (snapshot.hasData) {
        return MainPAge();
      } else {
        return MyLogin();
      }
    },
  );
}

【问题讨论】:

    标签: android flutter dart


    【解决方案1】:

    如果它一直处于等待状态,我的第一反应是检查您设备的连接性。编辑 AndroidManifest.xml 以允许 INTERNET_PERMISSION。我没有看到实际登录的方法,因此将状态更改为不等待,因此请确保它实际上正在被调用。

    【讨论】:

    • 我通过将项目设为 Androidx 解决了这个问题,但感谢您的帮助
    • 如何解决这个问题?我有同样的问题。
    猜你喜欢
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多