ошибка при реализации запроса на регистрацию пользователя
Привет я реализую регистрациюпользователя и столкнулся с ошибкой которую не могу решить код файла :`
import 'dart:js_interop';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:dio/dio.dart';
import 'package:auto_route/auto_route.dart';
import 'package:restapi_client/restapi_client.dart';
part 'signup_event.dart';
part 'signup_state.dart';
class SignupBloc extends Bloc<SignupEvent, SignupState> {
final RestApiClient restApiClient;
final StackRouter router;
SignupBloc({
required this.restApiClient,
required this.router,
}) : super(const SignupState()) {
on<SignupEvent>(_onEvent);
}
Future<void> _onEvent(SignupEvent event, Emitter<SignupState> emit) async {
if (event is SignupChangeFirstName) {
emit(state.copyWith(firstName: event.firstName));
} else if (event is SignupChangeLastName) {
emit(state.copyWith(lastName: event.lastName));
} else if (event is SignupChangeEmail) {
emit(state.copyWith(email: event.email));
} else if (event is SignupChangePassword) {
emit(state.copyWith(password: event.password));
} else if (event is SignupTry) {
await _attemptSignUp(emit);
}
}
Future<void> _attemptSignUp(Emitter<SignupState> emit) async {
emit(state.copyWith(loading: true));
try {
final RegisterResponse response = await restApiClient.userApi.register(
email: state.email,
password: state.password,
firstName: state.firstName,
lastName: state.lastName,
// Добавьте другие необходимые поля
);
if (response.token.isNotEmpty) {
restApiClient.onAuthTokenChanged(response.token, response.user);
await router.replace(MeetPeopleMapRoute());
} else {
emit(state.copyWith(loading: false, errorMessage: "Ошибка регистрации"));
}
}
catch (e) {
emit(state.copyWith(loading: false, errorMessage: "Произошла неизвестная ошибка: $e"));
}
}
}
// Маршрут MeetPeopleMapRoute, как определено в AppRouter class MeetPeopleMapRoute extends PageRouteInfo { MeetPeopleMapRoute() : super(name, args: '/map');
static const String name = 'MeetPeopleMapRoute'; }
[![вот фото ошибок ][1]][1]
Future<User> register(
String firstName,
String lastName,
String email,
String password,
) async {
try {
final resp = await dio.post<Map<String, dynamic>>(
'/user/register',
data: RegisterRequest(
firstName,
lastName,
email,
password,
).toJson(),
);
final result = RegisterResponse.fromJson(resp.data!);
tokenHandler.onAuthTokenChanged(result.token, result.user);
return result.user;
} catch (error, stackTrace) {
throwApiError(error, stackTrace);
}
}