Skip to content

Commit

Permalink
Merge pull request #79 from fga-eps-mds/feat(#119)/adiciona-injeçao-d…
Browse files Browse the repository at this point in the history
…e-dependencia-aos-arquivos

feat(#119): Adiciona GetIt em edit_profile
  • Loading branch information
GabrielCostaDeOliveira authored Jan 16, 2025
2 parents 1ebff0a + 7b03967 commit 60540a4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lib/core/di/locator.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:aranduapp/ui/edit_profile/di/di.dart';
import 'package:aranduapp/ui/login/di/di.dart';
import 'package:aranduapp/ui/register_account/di/di.dart';
import 'package:get_it/get_it.dart';
Expand All @@ -7,4 +8,5 @@ final GetIt locator = GetIt.instance;
void setupLocator() {
setupLoginDI();
setupRegisterDI();
setupEditProfileDI();
}
7 changes: 4 additions & 3 deletions lib/ui/edit_password/view/edit_password_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EditPassword extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => EditPasswordViewMode(),
create: (context) => EditPasswordViewModel(),
child: const EditPasswordScreen(),
);
}
Expand Down Expand Up @@ -59,7 +59,8 @@ class EditPasswordScreen extends StatelessWidget {
}

Widget _formSection(BuildContext context) {
EditPasswordViewMode viewModel = Provider.of<EditPasswordViewMode>(context);
EditPasswordViewModel viewModel =
Provider.of<EditPasswordViewModel>(context);

return Form(
key: viewModel.formKey,
Expand All @@ -78,7 +79,7 @@ class EditPasswordScreen extends StatelessWidget {
);
}

Widget _button(BuildContext context, EditPasswordViewMode viewModel) {
Widget _button(BuildContext context, EditPasswordViewModel viewModel) {
return Requestbutton(
command: viewModel.editCommand,
nameButton: "Enviar",
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/edit_password/viewmodel/edit_password_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import 'package:aranduapp/ui/edit_password/service/edit_password_service.dart';
import 'package:async/async.dart';
import 'package:flutter/material.dart';

class EditPasswordViewMode extends ChangeNotifier {
class EditPasswordViewModel extends ChangeNotifier {
final GlobalKey<FormState> formKey;
final TextEditingController newPasswordController;
final TextEditingController oldPasswordController;

late Command0<void> editCommand;

EditPasswordViewMode()
EditPasswordViewModel()
: formKey = GlobalKey<FormState>(),
newPasswordController = TextEditingController(),
oldPasswordController = TextEditingController() {
Expand Down
11 changes: 11 additions & 0 deletions lib/ui/edit_profile/di/di.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:aranduapp/ui/edit_profile/service/edit_profile_service.dart';
import 'package:aranduapp/ui/edit_profile/viewmodel/edit_profile_viewmodel.dart';
import 'package:get_it/get_it.dart';

final GetIt locator = GetIt.instance;

void setupEditProfileDI() {
locator.registerLazySingleton(() => EditProfileService());

locator.registerFactory(() => EditProfileViewModel());
}
4 changes: 1 addition & 3 deletions lib/ui/edit_profile/service/edit_profile_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import 'package:aranduapp/core/network/base_api.dart';
import 'package:aranduapp/ui/edit_profile/model/edit_profile_request.dart';

class EditProfileService {
static Future<void> edit(EditProfileRequest editProfileRequest) async {

Future<void> edit(EditProfileRequest editProfileRequest) async {
await BaseApi.getInstance(auth: true)
.patch(path: '/users', data: editProfileRequest.toJson());

}
}
6 changes: 4 additions & 2 deletions lib/ui/edit_profile/view/edit_profile_view.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import 'package:aranduapp/ui/edit_profile/viewmodel/edit_profile_viewmodel.dart';
import 'package:aranduapp/ui/login/viewmodel/login_viewmodel.dart';
import 'package:aranduapp/ui/shared/text_email.dart';
import 'package:aranduapp/ui/shared/text_name.dart';
import 'package:aranduapp/ui/shared/request_button.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';

class EditProfile extends StatelessWidget {
const EditProfile({super.key});

@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => EditProfileViewModel(),
return ChangeNotifierProvider<LoginViewModel>.value(
value: GetIt.instance<LoginViewModel>(),
child: const EditProfileScreen(),
);
}
Expand Down
11 changes: 5 additions & 6 deletions lib/ui/edit_profile/viewmodel/edit_profile_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:aranduapp/ui/edit_profile/model/edit_profile_request.dart';
import 'package:aranduapp/ui/edit_profile/service/edit_profile_service.dart';
import 'package:async/async.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';

class EditProfileViewModel extends ChangeNotifier {
final GlobalKey<FormState> formKey;
Expand All @@ -17,22 +18,20 @@ class EditProfileViewModel extends ChangeNotifier {
nameController = TextEditingController(),
userNameController = TextEditingController(),
emailController = TextEditingController() {

editCommand = Command0<void>(editprofile);

editCommand = Command0<void>(editProfile);
}

Future<Result<void>> editprofile() async {
Future<Result<void>> editProfile() async {
if (!formKey.currentState!.validate()) {
return Result.error(Exception('Valores inválidos' ));
return Result.error(Exception('Valores inválidos'));
}

EditProfileRequest request = EditProfileRequest(
name: nameController.text,
userName: userNameController.text,
email: emailController.text);

await EditProfileService.edit(request);
await GetIt.instance<EditProfileService>().edit(request);

return Result.value(null);
}
Expand Down

0 comments on commit 60540a4

Please sign in to comment.