Skip to content

Commit

Permalink
feat(#60) cria conexão com o servidor
Browse files Browse the repository at this point in the history
Co-authored-by: Yasm1nNasc1mento <[email protected]>
  • Loading branch information
GabrielCostaDeOliveira and Yasm1nNasc1mento committed Dec 13, 2024
1 parent 23823a8 commit 55bc995
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
16 changes: 16 additions & 0 deletions lib/ui/recover_account/model/RecoverAccountRequest.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dart:convert';

class RecoverAccountRequest {

final String email;

RecoverAccountRequest(this.email);

factory RecoverAccountRequest.fromJsonString(String jsonString) {
Map<String, dynamic> json = jsonDecode(jsonString);
return RecoverAccountRequest(
json['email'] as String,
);
}

}
17 changes: 17 additions & 0 deletions lib/ui/recover_account/service/RecoverAccountService.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:aranduapp/core/network/BaseApi.dart';
import 'package:aranduapp/ui/recover_account/model/RecoverAccountRequest.dart';

class RecoverAccountService {


static Future<void> forgetPassword(RecoverAccountRequest recoverAccountRequest) async {

await BaseApi.getInstance().post(
path: '/auth/forgot-password',
data: <String, dynamic> {
'email' : recoverAccountRequest.email,
}
);
}

}
11 changes: 8 additions & 3 deletions lib/ui/recover_account/view/RecoverAccount.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ Widget page(BuildContext context) {
child: SizedBox(
width: 291,
height: 64,
child:
ElevatedButton(onPressed: () {}, child: const Text('Enviar')),
child: ElevatedButton(
onPressed: () {},
child: Consumer<RecoverAccountViewModel>(
builder: (context, value, child) => value.isLoading
? const CircularProgressIndicator(value: null)
: const Text('Enviar'),
)),
),
),
TextAndLink(
text: 'Já tem uma conta?',
link: ' Click aqui',
link: 'Faça login',
action: () {
Navigator.of(context).pop();
},
Expand Down
42 changes: 41 additions & 1 deletion lib/ui/recover_account/viewModel/recoverAccountViewModel.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:aranduapp/ui/recover_account/model/RecoverAccountRequest.dart';
import 'package:aranduapp/ui/recover_account/service/RecoverAccountService.dart';
import 'package:flutter/material.dart';

class RecoverAccountViewModel extends ChangeNotifier {
Expand All @@ -7,7 +9,45 @@ class RecoverAccountViewModel extends ChangeNotifier {

final emailController;

final recoverAccountService;

bool isLoading;

RecoverAccountViewModel(this.context)
: formKey = GlobalKey<FormState>(),
emailController = TextEditingController();
emailController = TextEditingController(),
recoverAccountService = RecoverAccountService(),
isLoading = false;



Future<void> forgetPassword(String email) async {

// TODO use mutex to make this
if (isLoading){
return;
}

try {
isLoading = true;
super.notifyListeners();

if (!formKey.currentState!.validate()) {
throw Exception('Valores inválidos');
}

await recoverAccountService.forgetPassword(RecoverAccountRequest(email));

} catch (e) {
rethrow;
} finally {
isLoading = false;
super.notifyListeners();
}





}
}

0 comments on commit 55bc995

Please sign in to comment.