Flutter Project,Firebase登录无法正常工作并引发未处理的异常:类型“ FirebaseUser”不是类型“ bool”的子类型错误

时间:2020-04-18 06:48:52

标签: firebase flutter

Firebase Error screenshot

Pubspec.yaml (在App中使用Firebase版本)


firebase_core:^ 0.4.4 + 3 firebase_auth:^ 0.16.0

Build.gradle (应用中的Google Services版本)


classpath'com.google.gms:google-services:4.3.3'

Authservice.dart

header {
  flex: 0 0 50px;
}
.content {
  flex: 1 0 auto;
}

.footer {
    flex-shrink: 0;
    width: 100%;
    line-height: 60px; /* Vertically center the text there */
}

Signin.dart小部件

a.navbar-brand {
    white-space: normal;
    text-align: center;
    word-break: break-all;
}

/* Provide sufficient contrast against white background */
a {
    color: #0366d6;
}


.btn-primary {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}

.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}

/* Sticky footer styles
-------------------------------------------------- */
html {
    font-size: 14px;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

.border-top {
    border-top: 1px solid #e5e5e5;
}

.border-bottom {
    border-bottom: 1px solid #e5e5e5;
}

.box-shadow {
    box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}

button.accept-policy {
    font-size: 1rem;
    line-height: inherit;
}

/* Sticky footer styles
-------------------------------------------------- */
html {
    position: relative;
    min-height: 100%;
}

body {
    display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  flex: 0 0 50px;
}
.content {
  flex: 1 0 auto;
}

.footer {
    flex-shrink: 0;
    width: 100%;
    line-height: 60px; /* Vertically center the text there */
}

1 个答案:

答案 0 :(得分:0)

signInAnon返回一个FirebaseUser对象。

但是您正在使用if检查boolen条件。这就是为什么您会出错。而是进行null检查。试试这个:

onPressed: () async {
 var result = await _auth.signInAnon();
   if(result != null) {
     // your code
   } else {
     // error code
   }
 }