From d15eeb4f1ad61fd1624fbf4e1201d0afa9ab050c Mon Sep 17 00:00:00 2001 From: R1K4S Date: Mon, 16 Dec 2024 11:47:38 -0300 Subject: [PATCH] feat(#59) Criacao das pastas para o Modelo MVVM --- lib/main.dart | 3 +- lib/ui/profile/view/Profile.dart | 0 lib/ui/profile/view/ProfileView.dart | 44 ++++++++++++++ .../profile/viewModel/ProfileViewModel.dart | 57 +++++++++++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) delete mode 100644 lib/ui/profile/view/Profile.dart create mode 100644 lib/ui/profile/view/ProfileView.dart create mode 100644 lib/ui/profile/viewModel/ProfileViewModel.dart diff --git a/lib/main.dart b/lib/main.dart index 1b423e4..aa71e11 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'package:aranduapp/config/ThemeApp.dart'; import 'package:aranduapp/ui/login/view/LoginView.dart'; +import 'package:aranduapp/ui/profile/view/ProfileView.dart'; import 'package:aranduapp/ui/welcome/view/WelcomeView.dart'; import 'package:flutter/material.dart'; @@ -16,7 +17,7 @@ class MyApp extends StatelessWidget { theme: ThemeApp.themeData(), darkTheme: ThemeApp.darkThemeData(), debugShowCheckedModeBanner: false, - home: const Login(), + home: const Profile(), ); } } diff --git a/lib/ui/profile/view/Profile.dart b/lib/ui/profile/view/Profile.dart deleted file mode 100644 index e69de29..0000000 diff --git a/lib/ui/profile/view/ProfileView.dart b/lib/ui/profile/view/ProfileView.dart new file mode 100644 index 0000000..fa54290 --- /dev/null +++ b/lib/ui/profile/view/ProfileView.dart @@ -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), + ), + ), + ); +} diff --git a/lib/ui/profile/viewModel/ProfileViewModel.dart b/lib/ui/profile/viewModel/ProfileViewModel.dart new file mode 100644 index 0000000..dfa1c59 --- /dev/null +++ b/lib/ui/profile/viewModel/ProfileViewModel.dart @@ -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 formKey = GlobalKey(); + 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 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(); + } +}