Skip to content

Commit

Permalink
feat(#59) Criacao das pastas para o Modelo MVVM
Browse files Browse the repository at this point in the history
  • Loading branch information
R1K4S committed Dec 16, 2024
1 parent 732d328 commit d15eeb4
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -16,7 +17,7 @@ class MyApp extends StatelessWidget {
theme: ThemeApp.themeData(),
darkTheme: ThemeApp.darkThemeData(),
debugShowCheckedModeBanner: false,
home: const Login(),
home: const Profile(),
);
}
}
Empty file removed lib/ui/profile/view/Profile.dart
Empty file.
44 changes: 44 additions & 0 deletions lib/ui/profile/view/ProfileView.dart
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),
),
),
);
}
57 changes: 57 additions & 0 deletions lib/ui/profile/viewModel/ProfileViewModel.dart
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();
}
}

0 comments on commit d15eeb4

Please sign in to comment.