-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#59) Criacao das pastas para o Modelo MVVM
- Loading branch information
Showing
4 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'package:aranduapp/core/log/Log.dart'; | ||
import 'package:aranduapp/ui/profile/viewModel/ProfileViewModel.dart'; | ||
import 'package:aranduapp/ui/shared/ErrorPopUp.dart'; | ||
import 'package:aranduapp/ui/shared/TextAndLink.dart'; | ||
import 'package:aranduapp/ui/shared/TextEmail.dart'; | ||
import 'package:aranduapp/ui/shared/TitleSlogan.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class Profile extends StatelessWidget { | ||
const Profile({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: _appBar(), // Corrigido | ||
body: ChangeNotifierProvider( | ||
create: (context) => ProfileViewModel(context), | ||
builder: (context, child) { | ||
return _buildPage(context); | ||
}, | ||
), | ||
); | ||
} | ||
} | ||
|
||
AppBar _appBar() { | ||
return AppBar( | ||
title: const Text("Profile"), | ||
centerTitle: true, | ||
backgroundColor: Colors.blue, | ||
); | ||
} | ||
|
||
Widget _buildPage(BuildContext context) { | ||
return SingleChildScrollView( | ||
child: Center( | ||
child: const Text( | ||
'This is the next page', | ||
style: TextStyle(fontSize: 24), | ||
), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ProfileViewModel extends ChangeNotifier { | ||
final BuildContext context; | ||
|
||
// Controllers e Key para o formulário | ||
final GlobalKey<FormState> formKey = GlobalKey<FormState>(); | ||
final TextEditingController emailController = TextEditingController(); | ||
|
||
// Estado de carregamento | ||
bool _isLoading = false; | ||
bool get isLoading => _isLoading; | ||
|
||
ProfileViewModel(this.context); | ||
|
||
// Método para simular o envio do e-mail de recuperação de senha | ||
Future<void> forgetPassword() async { | ||
// Verifica se o formulário é válido | ||
if (!formKey.currentState!.validate()) { | ||
return; | ||
} | ||
|
||
_setLoading(true); | ||
|
||
try { | ||
// Simulação de chamada de API | ||
await Future.delayed(const Duration(seconds: 2)); | ||
|
||
// Validações ou chamadas reais para a API iriam aqui | ||
final email = emailController.text.trim(); | ||
if (email.isEmpty) { | ||
throw Exception("O campo de e-mail não pode estar vazio."); | ||
} | ||
|
||
// Log fictício para simular sucesso | ||
debugPrint("E-mail de recuperação enviado para: $email"); | ||
} catch (e) { | ||
// Relança a exceção para que o consumidor exiba o erro | ||
throw Exception("Erro ao enviar o e-mail: $e"); | ||
} finally { | ||
_setLoading(false); | ||
} | ||
} | ||
|
||
// Define o estado de carregamento e notifica os ouvintes | ||
void _setLoading(bool value) { | ||
_isLoading = value; | ||
notifyListeners(); | ||
} | ||
|
||
// Destruir controllers ao finalizar a ViewModel | ||
@override | ||
void dispose() { | ||
emailController.dispose(); | ||
super.dispose(); | ||
} | ||
} |