虽然setData方法中的这种收益不起作用,但是有人可以描述吗?如果没有从setData发送任何参数,那么它将起作用。或者任何人都可以解释它在bloc中的工作原理。
class LoginerrorBloc extends Bloc<LoginerrorEvent, LoginerrorState> {
@override
LoginerrorState get initialState => InitialLoginerrorState();
@override
Stream<LoginerrorState> mapEventToState(
LoginerrorEvent event,
) async* {
if (event is LoginEvent) {
yield LoginLoading();
try {
final url = apiUrl + 'login';
http.Response response = await http.post(url,
body: {'contact': event.contact, 'password': event.password});
if (response.statusCode == 200) {
// var res = Authenticate.fromJson(true);
yield* setData(Login.fromJson(jsonDecode(response.body)));
} else if (response.statusCode == 401) {
var res = LoginError.fromJson(jsonDecode(response.body));
yield LoginErrorState(res);
} else {
var res = LoginError.fromJson({'message': 'Internal Server Error'});
yield LoginErrorState(res);
}
} catch (e) {
var res = NetworkError.fromJson({'message': 'Internal Server Error'});
yield NetworkErrorState(res);
}
}
}
Stream<LoginerrorState> setData(data) async* {
yield AuthenticateState();
}
}