-
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.
- Loading branch information
1 parent
5dfd20c
commit 6d45993
Showing
9 changed files
with
251 additions
and
181 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'dart:convert'; | ||
|
||
class EditPasswordRequest { | ||
final String oldPassword; | ||
final String newPassword; | ||
|
||
EditPasswordRequest({ | ||
required this.oldPassword, | ||
required this.newPassword, | ||
}); | ||
|
||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'oldPassword': oldPassword, | ||
'newPassword': newPassword, | ||
}; | ||
} | ||
|
||
factory EditPasswordRequest.fromJsonString(String jsonString) { | ||
final json = jsonDecode(jsonString); | ||
|
||
return EditPasswordRequest( | ||
oldPassword: json['oldPpassword']! as String, | ||
newPassword: json['newPassword']! as String, | ||
); | ||
} | ||
} | ||
|
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,12 @@ | ||
import 'package:aranduapp/core/network/base_api.dart'; | ||
import 'package:aranduapp/ui/edit_password/model/edit_password_request.dart'; | ||
|
||
class EditPasswordService { | ||
|
||
static Future<void> edit(EditPasswordRequest editPasswordRequest) async { | ||
await BaseApi.getInstance(auth: true) | ||
.put(path: '/outh-change-password', data: editPasswordRequest.toJson()); | ||
} | ||
|
||
|
||
} |
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,96 @@ | ||
import 'package:aranduapp/ui/edit_password/viewmodel/edit_password_viewmode.dart'; | ||
import 'package:aranduapp/ui/shared/requestbutton.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
import 'package:aranduapp/ui/shared/TextPassword.dart'; | ||
|
||
class EditPassword extends StatelessWidget { | ||
const EditPassword({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ChangeNotifierProvider( | ||
create: (context) => EditPasswordViewMode(), | ||
child: const EditPasswordScreen(), | ||
); | ||
} | ||
} | ||
|
||
class EditPasswordScreen extends StatelessWidget { | ||
const EditPasswordScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
backgroundColor: Theme.of(context).colorScheme.surface, | ||
elevation: 0, | ||
title: Center( | ||
child: Text( | ||
'Editar Senha', | ||
style: TextStyle( | ||
color: Theme.of(context).colorScheme.onSurface, | ||
fontSize: 24, | ||
), | ||
), | ||
), | ||
leading: IconButton( | ||
color: Theme.of(context).colorScheme.primary, | ||
icon: const Icon(Icons.arrow_back), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
), | ||
body: _buildForm(context)); | ||
} | ||
|
||
Widget _buildForm(BuildContext context) { | ||
return SingleChildScrollView( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
children: [ | ||
const SizedBox(height: 10), | ||
_formSection(context), | ||
], | ||
), | ||
); | ||
} | ||
|
||
Widget _formSection(BuildContext context) { | ||
EditPasswordViewMode viewModel = Provider.of<EditPasswordViewMode>(context); | ||
|
||
return Form( | ||
key: viewModel.formKey, | ||
child: Column(children: [ | ||
TextPassWord( | ||
label: "Senha Antiga", | ||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20), | ||
controller: viewModel.oldPasswordController), | ||
TextPassWord( | ||
label: "Senha Nova", | ||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20), | ||
controller: viewModel.newPasswordController), | ||
const SizedBox(height: 80), | ||
_button(context, viewModel) | ||
]), | ||
); | ||
} | ||
|
||
Widget _button(BuildContext context, EditPasswordViewMode viewModel) { | ||
return Requestbutton( | ||
command: viewModel.editCommand, | ||
nameButton: "Enviar", | ||
onErrorCallback: (e) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar(content: Text(e)), | ||
); | ||
}, | ||
onSuccessCallback: () { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('Senha atualizada com sucesso')), | ||
); | ||
}); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
lib/ui/edit_password/viewmodel/edit_password_viewmode.dart
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,34 @@ | ||
import 'package:aranduapp/core/state/command.dart'; | ||
import 'package:aranduapp/ui/edit_password/model/edit_password_request.dart'; | ||
import 'package:aranduapp/ui/edit_password/service/edit_password_service.dart'; | ||
import 'package:async/async.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class EditPasswordViewMode extends ChangeNotifier { | ||
final GlobalKey<FormState> formKey; | ||
final TextEditingController newPasswordController; | ||
final TextEditingController oldPasswordController; | ||
|
||
late Command0<void> editCommand; | ||
|
||
EditPasswordViewMode() | ||
: formKey = GlobalKey<FormState>(), | ||
newPasswordController = TextEditingController(), | ||
oldPasswordController = TextEditingController() { | ||
editCommand = Command0<void>(editPassword); | ||
} | ||
|
||
Future<Result<void>> editPassword() async { | ||
if (!formKey.currentState!.validate()) { | ||
return Result.error(Exception('Valores inválidos')); | ||
} | ||
|
||
EditPasswordRequest request = EditPasswordRequest( | ||
oldPassword: oldPasswordController.text, | ||
newPassword: newPasswordController.text); | ||
|
||
await EditPasswordService.edit(request); | ||
|
||
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
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
Oops, something went wrong.