【问题标题】:A value of type 'Stream<User?>' can't be returned from the function 'user' because it has a return type of 'Stream<User>?'无法从函数“user”返回类型为“Stream<User?>”的值,因为它的返回类型为“Stream<User>?”
【发布时间】:2021-10-02 20:41:40
【问题描述】:

我在 auth.authStateChanges() 上得到红线, 错误提示:无法从函数“user”返回类型为“Stream”的值,因为它的返回类型为“Stream?”。

class Auth {
  final FirebaseAuth auth;

  Auth({required this.auth});

  Stream<User>? get user => auth.authStateChanges(); <-- here

现在更新我得到这个错误:

Future<String?> createAccount({required String email, required String password}) async {
    try {
      await auth.createUserWithEmailAndPassword( <-- here **auth**
        email: email.trim(),
        password: password.trim(),
      );
      return "Success";
    } on FirebaseAuthException catch (e) {
      return e.message;
    } catch (e) {
      rethrow;
    }
  }

【问题讨论】:

  • Stream&lt;User?&gt; get user 更改了 Stream 上的可为空值?
  • @RaineDaleHolgado 现在我在 auth 下遇到错误:未定义的名称“auth”。查看更新

标签: flutter flutter-layout


【解决方案1】:

这是你更新的课程

import 'package:firebase_auth/firebase_auth.dart';

class Auth {
  final FirebaseAuth auth;

  Auth({required this.auth});

  Stream<User?> get user => auth.authStateChanges();

  Future<String?> createAccount({required String email, required String password}) async {
    try {
      await FirebaseAuth.instance.createUserWithEmailAndPassword(
        email: email.trim(),
        password: password.trim(),
      );
      return "Success";
    } on FirebaseAuthException catch (e) {
      return e.message;
    } catch (e) {
      rethrow;
    }
  }
}

【讨论】:

    猜你喜欢
    • 2021-08-20
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2022-10-12
    • 2021-09-04
    • 1970-01-01
    • 2021-10-05
    • 1970-01-01
    相关资源
    最近更新 更多