【问题标题】:The getter 'onAuthStateChanged' isn't defined for the type 'FirebaseAuth'. Try importing the library that defines 'onAuthStateChanged'没有为“FirebaseAuth”类型定义吸气剂“onAuthStateChanged”。尝试导入定义“onAuthStateChanged”的库
【发布时间】:2021-09-08 03:38:22
【问题描述】:

没有为“FirebaseAuth”类型定义吸气剂“onAuthStateChanged”。 尝试导入定义“onAuthStateChanged”的库,将名称更正为现有 getter 的名称,或定义名为“onAuthStateChanged”的 getter 或字段 谢谢 代码在下面..

import 'package:brew_crew/model/user.dart';
import 'package:firebase_auth/firebase_auth.dart';

class AuthService{

  final FirebaseAuth _auth = FirebaseAuth.instance;

  // Create user object based on FirebaseUser
  CurrentUser? _customModelForFirebaseUser(User user) {
    return user != null ? CurrentUser (uid: user.uid) : null;
  }

   
   // auth changed user stream
  Stream<CurrentUser > get user {
    return _auth.onAuthStateChanged // here is the problem
      .map(_customModelForFirebaseUser);
  }
  
  //sin in anon
  Future signInAnon() async{
   try {
  UserCredential result = await _auth.signInAnonymously();
  User? user = result.user;
  return _customModelForFirebaseUser(user!);
}catch (e) {
  print(e.toString());
  return null;
}

  }

  //sign in with E-mail and password

  //Register with E-mail and passqord

  //Sign out
}

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    从 firebase 0.18.0 开始,他们对某些类进行了细微的更改。

    不要使用 _auth.onAuthStateChanged,而是使用 _auth.authStateChanges

    【讨论】:

      猜你喜欢
      • 2021-09-17
      • 2021-04-14
      • 1970-01-01
      • 2021-03-26
      • 2020-12-07
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      相关资源
      最近更新 更多