【发布时间】:2021-03-08 23:32:24
【问题描述】:
我正在尝试开始使用 Freezed,我在下面定义了这个类,而我的应用程序的其余部分似乎没有发现它具有 id 属性:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'user.freezed.dart';
@freezed
abstract class VpUser implements _$VpUser {
factory VpUser({String id, User firebaseUser}) = _VpUser;
const factory VpUser.empty() = _Empty;
const VpUser._();
}
我在身份验证服务中使用该类:
class AuthenticationService extends VpService {
final FirebaseAuth _auth = FirebaseAuth.instance;
final Rx<User> _firebaseUser = Rx<User>();
VpUser get user =>
VpUser(id: _firebaseUser.value?.uid, firebaseUser: _firebaseUser.value);
然后我像这样调用附加到 AuthService 的用户:
if (_authenticationService.user.id != null) {
我有错误:
错误:没有为类“VpUser”定义吸气剂“id”。
- “VpUser”来自“package:vepo/domain/auth/user.dart”(“lib/domain/auth/user.dart”)。尝试将名称更正为 现有的 getter,或定义名为“id”的 getter 或字段。 if (_authenticationService.user.id != null) {
如何在VpUser 中声明 id 以便其他类可以访问它?
【问题讨论】: