diff --git a/lib/data/repository/account_repository.dart b/lib/data/repository/account_repository.dart index cbb2dd2..fa0dc75 100644 --- a/lib/data/repository/account_repository.dart +++ b/lib/data/repository/account_repository.dart @@ -104,6 +104,7 @@ class AccountRepository { if (user.id == null || user.id!.isEmpty) { throw BadRequestException(userIdNotNull); } + user = user.copyWith(langKey: user.langKey ?? "en"); final httpResponse = await HttpUtils.postRequest("/$_resource", user); final response = HttpUtils.decodeUTF8(httpResponse.body.toString()); var result = User.fromJsonString(response)!; diff --git a/lib/presentation/common_blocs/account/account_bloc.dart b/lib/presentation/common_blocs/account/account_bloc.dart index eb2d2b2..6937685 100644 --- a/lib/presentation/common_blocs/account/account_bloc.dart +++ b/lib/presentation/common_blocs/account/account_bloc.dart @@ -4,7 +4,6 @@ import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc_advance/configuration/app_logger.dart'; import 'package:flutter_bloc_advance/configuration/local_storage.dart'; -import 'package:flutter_bloc_advance/data/repository/user_repository.dart'; import '../../../data/models/user.dart'; import '../../../data/repository/account_repository.dart'; @@ -26,8 +25,6 @@ class AccountBloc extends Bloc { on(_onSubmit); } - final UserRepository _userRepository = UserRepository(); - /// Load the current account. FutureOr _onFetchAccount(AccountFetchEvent event, Emitter emit) async { _log.debug("BEGIN: getAccount bloc: _onLoad"); @@ -50,7 +47,7 @@ class AccountBloc extends Bloc { _log.debug("BEGIN: onSubmit AccountSubmitEvent event: {}", [event.data.toString()]); emit(state.copyWith(status: AccountStatus.loading)); try { - final user = await _userRepository.update(event.data); + final user = await _repository.update(event.data); emit(state.copyWith(status: AccountStatus.success, data: user)); _log.debug("END:onSubmitAccountSubmitEvent event success: {}", [user.toString()]); } catch (e) { diff --git a/lib/presentation/screen/account/account_screen.dart b/lib/presentation/screen/account/account_screen.dart index 061ac20..9e1e8f2 100644 --- a/lib/presentation/screen/account/account_screen.dart +++ b/lib/presentation/screen/account/account_screen.dart @@ -47,8 +47,16 @@ class AccountScreen extends StatelessWidget { return BlocBuilder( buildWhen: (previous, current) => previous.status != current.status, builder: (context, state) { + // final initialValues = { + // 'login': state.data?.login, + // 'firstName': state.data?.firstName, + // 'lastName': state.data?.lastName, + // 'email': state.data?.email + // }; + return ResponsiveFormBuilder( formKey: _formKey, + // initialValue: initialValues, children: [..._buildFormFields(context, state), _submitButton(context, state)], ); }, @@ -61,7 +69,7 @@ class AccountScreen extends StatelessWidget { UserFormFields.firstNameField(context, state.data?.firstName), UserFormFields.lastNameField(context, state.data?.lastName), UserFormFields.emailField(context, state.data?.email), - UserFormFields.activatedField(context, state.data?.activated), + //UserFormFields.activatedField(context, state.data?.activated), ]; } @@ -91,6 +99,8 @@ class AccountScreen extends StatelessWidget { final formData = _formKey.currentState!.value; final user = _createUserFromData(formData, state.data?.id); context.read().add(AccountSubmitEvent(user)); + _formKey.currentState?.save(); + context.read().add(const AccountFetchEvent()); } } @@ -113,6 +123,7 @@ class AccountScreen extends StatelessWidget { break; case AccountStatus.success: _showSnackBar(context, S.of(context).success, duration); + //_formKey.currentState?.reset(); break; case AccountStatus.failure: _showSnackBar(context, S.of(context).failed, duration);