-
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.
Merge pull request #83 from fga-eps-mds/feat#59/profile_logout
feat(\#59): implementa logout
- Loading branch information
Showing
4 changed files
with
392 additions
and
113 deletions.
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
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 |
---|---|---|
@@ -1,56 +1,20 @@ | ||
import 'package:aranduapp/core/log/log.dart'; | ||
import 'package:aranduapp/core/state/command.dart'; | ||
import 'package:async/async.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:aranduapp/core/data/local/storage_value.dart'; | ||
|
||
class ProfileViewModel extends ChangeNotifier { | ||
// Controllers e Key para o formulário | ||
final GlobalKey<FormState> formKey = GlobalKey<FormState>(); | ||
final TextEditingController emailController = TextEditingController(); | ||
late Command0<void> logoutCommand; | ||
|
||
// Estado de carregamento | ||
bool _isLoading = false; | ||
bool get isLoading => _isLoading; | ||
|
||
// ProfileViewModel não precisa mais do BuildContext | ||
ProfileViewModel(); | ||
|
||
// 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); | ||
} | ||
ProfileViewModel() { | ||
logoutCommand = Command0<void>(logout); | ||
} | ||
|
||
// Define o estado de carregamento e notifica os ouvintes | ||
void _setLoading(bool value) { | ||
_isLoading = value; | ||
notifyListeners(); | ||
} | ||
Future<Result<void>> logout() async { | ||
await StorageValue.getInstance().clear(); | ||
|
||
// Destruir controllers ao finalizar a ViewModel | ||
@override | ||
void dispose() { | ||
emailController.dispose(); | ||
super.dispose(); | ||
Log.d("Usuário deslogado com sucesso."); | ||
return Result.value(null); | ||
} | ||
} |
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
Oops, something went wrong.