-
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 #56 from fga-eps-mds/qa/register_account
Qa/register account
- Loading branch information
Showing
12 changed files
with
620 additions
and
98 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,47 @@ | ||
import 'package:async/async.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
abstract class Command<T> extends ChangeNotifier { | ||
Result<T>? _result; | ||
|
||
bool _running = false; | ||
|
||
Command(); | ||
|
||
bool get isError => result?.asError != null; | ||
|
||
bool get isOk => result?.asValue != null; | ||
|
||
Result<T>? get result => _result; | ||
|
||
bool get running => _running; | ||
|
||
Future<void> _execute(action) async { | ||
if (running) return; | ||
|
||
_result = null; | ||
_running = true; | ||
notifyListeners(); | ||
|
||
try { | ||
_result = await action(); | ||
} catch (e) { | ||
_result = Result.error(e); | ||
} finally { | ||
_running = false; | ||
notifyListeners(); | ||
} | ||
} | ||
} | ||
|
||
class Command0<T> extends Command<T> { | ||
final Future<Result<T>> Function() action; | ||
|
||
Command0(this.action); | ||
|
||
Future<Result<T>> execute() async { | ||
await _execute(action); | ||
|
||
return _result!; | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ster_account/service/RegisterService.dart → ...ter_account/service/register_service.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
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 was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
lib/ui/register_account/viewModel/register_view_model.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,47 @@ | ||
import 'package:aranduapp/core/state/command.dart'; | ||
import 'package:async/async.dart'; | ||
import 'package:flutter/material.dart'; | ||
import '../model/register_request.dart'; | ||
import '../service/register_service.dart'; | ||
|
||
class RegisterAccountViewModel extends ChangeNotifier { | ||
final GlobalKey<FormState> formKey = GlobalKey<FormState>(); | ||
final TextEditingController nameController = TextEditingController(); | ||
final TextEditingController emailController = TextEditingController(); | ||
final TextEditingController userNameController = TextEditingController(); | ||
final TextEditingController passwordController = TextEditingController(); | ||
|
||
bool isTermsAccepted = false; | ||
|
||
late Command0<void> registerCommand; | ||
|
||
RegisterAccountViewModel() { | ||
registerCommand = Command0<void>(_register); | ||
} | ||
|
||
Future<Result<void>> _register() async { | ||
|
||
if (!isTermsAccepted) { | ||
return Result.error( | ||
'Você deve aceitar os termos de privacidade e políticas de uso.'); | ||
} | ||
|
||
if (!formKey.currentState!.validate()) { | ||
Result.error('Por favor, preencha todos os campos corretamente'); | ||
} | ||
|
||
await RegisterService.register(RegisterRequest( | ||
email: emailController.text, | ||
name: nameController.text, | ||
userName: userNameController.text, | ||
password: passwordController.text, | ||
)); | ||
|
||
return Result.value(null); | ||
} | ||
|
||
void toggleTermsAccepted(bool value) { | ||
isTermsAccepted = value; | ||
notifyListeners(); | ||
} | ||
} |
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.