I'm following this tutorial https://bloclibrary.dev/#/flutterlogintutorial?id=login-bloc . Now i'm trying to add new parameter for result message .
yield state.copyWith(status: FormzStatus.submissionSuccess, message: "Success");
Below is my whole function
Stream<RegisterState> _mapRegisterSubmittedToState(
RegisterSubmitted event,
RegisterState state,
) async* {
if (state.status.isValidated) {
yield state.copyWith(status: FormzStatus.submissionInProgress);
FormData data = FormData.fromMap({
'email': state.email.value,
'password': state.password.value,
'phone': state.phone.value,
'language': 'indonesia'
});
try {
Dio dio = new Dio();
final process = await dio.post(SourceApi().ipAddress + 'Gate/register/', data: data);
if (process.statusCode == 200) {
yield state.copyWith(status: FormzStatus.submissionSuccess, message: "Success");
} else {
yield state.copyWith(status: FormzStatus.submissionFailure, message: "Failed");
}
} on Exception catch (_) {
yield state.copyWith(status: FormzStatus.submissionFailure);
}
yield state.copyWith(status: FormzStatus.submissionSuccess);
} else {
yield state.copyWith(status: FormzStatus.submissionFailure);
}
}
when i'm trying to change my state to this
class RegisterState extends Equatable {
const RegisterState(
{this.status = FormzStatus.pure,
this.email = const Email.pure(),
this.password = const Password.pure(),
this.phone = const Phone.pure(),
this.message = message});
final FormzStatus status;
final Email email;
final Password password;
final Phone phone;
final String message;
RegisterState copyWith(
{FormzStatus status, Email email, Password password, Phone phone, String message}) {
return RegisterState(
status: status ?? this.status,
email: email ?? this.email,
password: password ?? this.password,
phone: phone ?? this.phone,
message: message ?? this.message);
}
@override
List<Object> get props => [status, email, password, phone, message];
}
I get this error
Compiler message:
lib/register/bloc/register_state.dart:9:22: Error: Getter not found: 'message'.
this.message = message});
how can i fix it ?
Hi @bobykurniawan11 馃憢
Thanks for opening an issue!
It looks like the issue is you're not provided a valid default value to message.
class RegisterState extends Equatable {
const RegisterState({
this.status = FormzStatus.pure,
this.email = const Email.pure(),
this.password = const Password.pure(),
this.phone = const Phone.pure(),
this.message = '', // this was incorrect previously
});
final FormzStatus status;
final Email email;
final Password password;
final Phone phone;
final String message;
RegisterState copyWith(
{FormzStatus status, Email email, Password password, Phone phone, String message}) {
return RegisterState(
status: status ?? this.status,
email: email ?? this.email,
password: password ?? this.password,
phone: phone ?? this.phone,
message: message ?? this.message);
}
@override
List<Object> get props => [status, email, password, phone, message];
}
Hope that helps 馃憤
thank you. it is fix my problem
Most helpful comment
thank you. it is fix my problem