Skip to content

Commit

Permalink
fix(#58): corrige arquitetura
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielCostaDeOliveira committed Dec 20, 2024
1 parent 62a0856 commit 43a755a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 63 deletions.
96 changes: 50 additions & 46 deletions lib/ui/recover_account/view/RecoverAccount.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,48 @@ class RecoverAccount extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: ChangeNotifierProvider(
create: (context) => RecoverAccountViewModel(context),
create: (context) => RecoverAccountViewModel(),
builder: (context, child) {
return page(context);
return const RecoverAccountScreen();
}),
);
}
}

Widget page(BuildContext context) {
RecoverAccountViewModel viewModel =
Provider.of<RecoverAccountViewModel>(context);
class RecoverAccountScreen extends StatelessWidget {
const RecoverAccountScreen({super.key});

return SingleChildScrollView(
child: Center(
child: Column(
children: <Widget>[
const SizedBox(height: 80),
const TitleSlogan(),
const Padding(
padding: EdgeInsets.only(top: 70, left: 20, right: 20),
child: Text(
'Coloque o seu e-mail no campo abaixo e clique em enviar. Logo em seguida, você receberá no seu e-mail as instruções para trocar a sua senha.',
@override
Widget build(BuildContext context) {
RecoverAccountViewModel viewModel =
Provider.of<RecoverAccountViewModel>(context);

return SingleChildScrollView(
child: Center(
child: Column(
children: <Widget>[
const SizedBox(height: 80),
const TitleSlogan(),
const Padding(
padding: EdgeInsets.only(top: 70, left: 20, right: 20),
child: Text(
'Coloque o seu e-mail no campo abaixo e clique em enviar. Logo em seguida, você receberá no seu e-mail as instruções para trocar a sua senha.',
),
),
),
Form(
key: viewModel.formKey,
child: Column(children: <Widget>[
TextEmail(
padding:
const EdgeInsets.only(top: 24, left: 20, right: 20),
controller: viewModel.emailController),
])),
Padding(
padding: const EdgeInsets.only(top: 80),
child: SizedBox(
width: 291,
height: 64,
child: ElevatedButton(
Form(
key: viewModel.formKey,
child: Column(children: <Widget>[
TextEmail(
padding:
const EdgeInsets.only(top: 24, left: 20, right: 20),
controller: viewModel.emailController),
])),
Padding(
padding: const EdgeInsets.only(top: 80),
child: SizedBox(
width: 291,
height: 64,
child: ElevatedButton(
onPressed: () {
viewModel.forgetPassword().then((value) {
Log.d("Deu certo!");
Expand All @@ -61,22 +65,22 @@ Widget page(BuildContext context) {
ErrorPopUp(content: Text('$e')),
));
},
child: Consumer<RecoverAccountViewModel>(
builder: (context, value, child) => value.isLoading
? const CircularProgressIndicator(value: null)
: const Text('Enviar'),
)),
child: viewModel.isLoading
? const CircularProgressIndicator(value: null)
: const Text('Enviar'),
),
),
),
),
TextAndLink(
text: 'Já tem uma conta?',
link: 'Faça login',
action: () {
Navigator.of(context).pop();
},
)
],
TextAndLink(
text: 'Já tem uma conta?',
link: 'Faça login',
action: () {
Navigator.of(context).pop();
},
)
],
),
),
),
);
);
}
}
23 changes: 6 additions & 17 deletions lib/ui/recover_account/viewModel/recoverAccountViewModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@ import 'package:aranduapp/ui/recover_account/service/RecoverAccountService.dart'
import 'package:flutter/material.dart';

class RecoverAccountViewModel extends ChangeNotifier {
final BuildContext context;

final formKey;

final emailController;
GlobalKey<FormState> formKey;

TextEditingController emailController;

bool isLoading;

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



Future<void> forgetPassword() async {

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

Expand All @@ -35,18 +29,13 @@ class RecoverAccountViewModel extends ChangeNotifier {
throw Exception('Valores inválidos');
}

await RecoverAccountService.forgetPassword(RecoverAccountRequest(emailController.text));

await RecoverAccountService.forgetPassword(
RecoverAccountRequest(emailController.text));
} catch (e) {
rethrow;
} finally {
isLoading = false;
super.notifyListeners();
}





}
}
Empty file.

0 comments on commit 43a755a

Please sign in to comment.