2
  void emailChanged(String value) {
    final email = Email.dirty(value);
    emit(state.copyWith(
      email: email,
      status: Formz.validate([email, state.password]),
    ));
  }

这是我的简单功能。状态给出错误我不知道为什么。所有软件包都已安装(flutter_bloc)。为什么它给出一个错误?

Undefined name 'state'.
Try correcting the name to one that is defined, or defining the name

我的状态:

part of 'login_cubit.dart';

class LoginState extends Equatable {
  const LoginState({
    this.email = const Email.pure(),
    this.password = const Password.pure(),
    this.username = const Username.pure(),
    this.status = FormzStatus.pure,
    this.exceptionError = "",
  });

  final Email email;
  final Username username;
  final Password password;
  final FormzStatus status;
  final String exceptionError;

  @override
  List<Object> get props =>
      [email, username, password, status, exceptionError];

  LoginState copyWith({
    Email? email,
    Username? username,
    Password? password,
    FormzStatus? status,
    String? exceptionError,
  }) {
    return LoginState(
      email: email ?? this.email,
      username: username ?? this.username,
      password: password ?? this.password,
      status: status ?? this.status,
      exceptionError: exceptionError ?? this.exceptionError,
    );
  }
}

昨天没报错,是不是包坏了?

4

2 回答 2

1
flutter pub cache repair

然后删除 pubspec.lock

flutter pub get

感谢 Rolly Mod

于 2021-10-11T20:40:35.693 回答
0

我认为在 emailChanged() 的独家新闻中,您尝试发出的变量“状态”是未知的。

尝试将其作为参数传递

void emailChanged(String value, <YOUR_TIPE> state) {
final email = Email.dirty(value);
emit(state.copyWith(
  email: email,
  status: Formz.validate([email, state.password]),
));

}

于 2021-10-11T20:38:28.493 回答