-
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 #23 from fga-eps-mds/feat#59/Tela-de-EditProfile
Feat#59/tela de edit profile
- Loading branch information
Showing
9 changed files
with
268 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
description: This file stores settings for Dart & Flutter DevTools. | ||
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states | ||
extensions: |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'dart:convert'; | ||
|
||
class EditProfileRequest { | ||
final String? email; | ||
final String? password; | ||
|
||
EditProfileRequest(this.email, this.password); | ||
|
||
factory EditProfileRequest.fromJsonString(String jsonString) { | ||
Map<String, dynamic> json = jsonDecode(jsonString); | ||
return EditProfileRequest( | ||
json['email'] as String?, | ||
json['password'] as String?, | ||
); | ||
} | ||
} |
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,14 @@ | ||
import 'package:aranduapp/ui/edit_profile/model/EditProfileRequest.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
class EditProfileService { | ||
static Future<Response> edit(EditProfileRequest editProfileRequest) async { | ||
// TODO: implement build | ||
throw UnimplementedError(); | ||
} | ||
|
||
static Future<EditProfileRequest> refreshToken() async { | ||
// TODO: implement build | ||
throw UnimplementedError(); | ||
} | ||
} |
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,136 @@ | ||
import 'package:aranduapp/ui/shared/TextName.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
import 'package:aranduapp/ui/edit_profile/viewModel/EditProfileViewModel.dart'; | ||
import 'package:aranduapp/ui/shared/TextEmail.dart'; | ||
import 'package:aranduapp/ui/shared/TextPassword.dart'; | ||
|
||
class EditProfile extends StatelessWidget { | ||
const EditProfile({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ChangeNotifierProvider( | ||
create: (context) => EditProfileViewModel(context), | ||
child: const EditProfileScreen(), | ||
); | ||
} | ||
} | ||
|
||
class EditProfileScreen extends StatefulWidget { | ||
const EditProfileScreen({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<EditProfileScreen> createState() => _EditProfileScreenState(); | ||
} | ||
|
||
class _EditProfileScreenState extends State<EditProfileScreen> { | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final viewModel = Provider.of<EditProfileViewModel>(context); | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Editar Perfil'), | ||
), | ||
body: _buildForm(viewModel) | ||
); | ||
} | ||
|
||
Widget _buildForm(EditProfileViewModel viewModel) { | ||
return SingleChildScrollView( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Form( | ||
key: viewModel.formKey, | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
|
||
TextName( | ||
controller: viewModel.firstNameController, | ||
padding: const EdgeInsets.symmetric(vertical: 16) | ||
), | ||
|
||
TextEmail( | ||
padding: const EdgeInsets.symmetric(vertical: 16), | ||
controller: viewModel.emailController, | ||
), | ||
|
||
TextPassWord( | ||
padding: const EdgeInsets.symmetric(vertical: 16), | ||
controller: viewModel.passwordController, | ||
), | ||
|
||
const SizedBox(height: 32), | ||
_saveButton(viewModel), | ||
const SizedBox(height: 16), | ||
_deleteButton(context), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget _saveButton(EditProfileViewModel viewModel) { | ||
return ElevatedButton( | ||
onPressed: () async { | ||
if (viewModel.isLoading) return; | ||
try { | ||
await viewModel.editprofileWithEmailAndPassword(); | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('Perfil atualizado com sucesso!')), | ||
); | ||
} catch (e) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar(content: Text('Erro: $e')), | ||
); | ||
} | ||
}, | ||
|
||
child: Consumer<EditProfileViewModel>( | ||
builder: (context, value, child) => value.isLoading | ||
? const CircularProgressIndicator(value: null) | ||
: const Text('Salvar'), | ||
), | ||
|
||
); | ||
} | ||
|
||
Widget _deleteButton(BuildContext context) { | ||
return ElevatedButton( | ||
onPressed: () => _showDeleteConfirmationDialog(context), | ||
child: const Text('Deletar Conta'), | ||
); | ||
} | ||
|
||
void _showDeleteConfirmationDialog(BuildContext context) { | ||
showDialog( | ||
context: context, | ||
builder: (BuildContext context) { | ||
return AlertDialog( | ||
title: const Text('Confirmar Deleção'), | ||
content: const Text( | ||
'Tem certeza de que deseja deletar sua conta? Essa ação não pode ser desfeita.'), | ||
actions: [ | ||
TextButton( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
child: const Text('Cancelar'), | ||
), | ||
ElevatedButton( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('Conta deletada com sucesso!')), | ||
); | ||
}, | ||
child: const Text('Deletar'), | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
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,65 @@ | ||
import 'package:aranduapp/core/log/Log.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:aranduapp/ui/edit_profile/service/EditProfileService.dart'; | ||
import 'package:aranduapp/ui/edit_profile/model/EditProfileRequest.dart'; | ||
|
||
class EditProfileViewModel extends ChangeNotifier { | ||
final BuildContext context; | ||
|
||
bool isLoading; | ||
final GlobalKey<FormState> formKey; | ||
final TextEditingController firstNameController; | ||
final TextEditingController lastNameController; | ||
final TextEditingController emailController; | ||
final TextEditingController passwordController; | ||
|
||
// Inicialização dos campos no construtor | ||
EditProfileViewModel(this.context) | ||
: isLoading = false, | ||
formKey = GlobalKey<FormState>(), | ||
firstNameController = TextEditingController(), | ||
lastNameController = TextEditingController(), | ||
emailController = TextEditingController(), | ||
passwordController = TextEditingController(); | ||
|
||
Future<void> editprofileWithEmailAndPassword() async { | ||
if (isLoading) { | ||
return; | ||
} | ||
|
||
try { | ||
isLoading = true; | ||
notifyListeners(); | ||
|
||
if (!formKey.currentState!.validate()) { | ||
throw Exception('Valores inválidos'); | ||
} | ||
|
||
|
||
await Future.delayed(const Duration(seconds: 10)); | ||
|
||
|
||
// await EditProfileService.edit( | ||
// EditProfileRequest(emailController.text, passwordController.text)); | ||
|
||
} catch (e) { | ||
rethrow; | ||
} finally { | ||
isLoading = false; | ||
notifyListeners(); | ||
} | ||
} | ||
|
||
Future<void> getRefreshTokenFuture() async { | ||
try { | ||
// Exemplo de simulação de uma operação assíncrona: | ||
await Future.delayed(const Duration(seconds: 2)); | ||
// Aqui você deve chamar o serviço real que renova o token de autenticação. | ||
// Exemplo: | ||
// await LoginService.refreshToken(); | ||
} catch (e) { | ||
throw Exception('Erro ao renovar o token: $e'); | ||
} | ||
} | ||
} |
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,33 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class TextName extends StatelessWidget{ | ||
|
||
|
||
final TextEditingController controller; | ||
final EdgeInsetsGeometry padding; | ||
|
||
|
||
const TextName({ | ||
super.key, | ||
required this.controller, | ||
required this.padding, | ||
}); | ||
|
||
|
||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: padding, | ||
child: TextFormField( | ||
validator: (value) => value == null || value.trim().length < 3 ? 'Nome inválido' : null , | ||
controller: controller, | ||
decoration: InputDecoration ( | ||
prefixIcon: Icon ( Icons.person_outline, color: Theme.of(context).colorScheme.primary), | ||
labelText: 'Nome' | ||
), | ||
), | ||
); | ||
} | ||
|
||
} |