Skip to content

Commit

Permalink
Merge branch 'dev' into fix#00/altera-nome-arquivos
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielCostaDeOliveira committed Jan 15, 2025
2 parents f30882e + ee8b998 commit cc6097c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 15 deletions.
8 changes: 8 additions & 0 deletions lib/core/di/locator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:aranduapp/ui/login/di/di.dart';
import 'package:get_it/get_it.dart';

final GetIt locator = GetIt.instance;

void setupLocator() {
setupLoginDI();
}
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:aranduapp/config/theme_app.dart';
import 'package:aranduapp/ui/welcome/view/welcome_view.dart';
import 'package:aranduapp/core/di/locator.dart';
import 'package:flutter/material.dart';

void main() {
Expand All @@ -11,6 +12,9 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {

setupLocator();

return MaterialApp(
theme: ThemeApp.themeData(),
darkTheme: ThemeApp.darkThemeData(),
Expand Down
12 changes: 12 additions & 0 deletions lib/ui/login/di/di.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:aranduapp/ui/login/service/login_service.dart';
import 'package:aranduapp/ui/login/viewmodel/login_viewmodel.dart';
import 'package:get_it/get_it.dart';

final GetIt locator = GetIt.instance;

void setupLoginDI() {

locator.registerLazySingleton(() => LoginService());

locator.registerFactory(() => LoginViewModel());
}
4 changes: 2 additions & 2 deletions lib/ui/login/service/login_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:aranduapp/ui/login/model/login_response.dart';
import 'package:dio/dio.dart';

class LoginService {
static Future<Response> login(LoginRequest loginRequest) async {
Future<Response> login(LoginRequest loginRequest) async {
Log.d('${loginRequest.email} ${loginRequest.password}');

Response response = await BaseApi.getInstance(auth: false).post(
Expand All @@ -27,7 +27,7 @@ class LoginService {
return response;
}

static Future<void> validateToken() async {
Future<void> validateToken() async {
await AuthService().refreshToken();
}
}
6 changes: 3 additions & 3 deletions lib/ui/login/view/login_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:aranduapp/ui/navbar/view/navbar_view.dart';
import 'package:aranduapp/ui/shared/text_and_link.dart';
import 'package:aranduapp/ui/shared/request_button.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

Expand All @@ -19,11 +20,10 @@ import 'package:aranduapp/ui/shared/or_divider.dart';

class Login extends StatelessWidget {
const Login({super.key});

@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => LoginViewModel(),
return ChangeNotifierProvider<LoginViewModel>.value(
value: GetIt.instance<LoginViewModel>(),
child: const LoginScreen(),
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/login/viewmodel/login_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:aranduapp/core/log/log.dart';
import 'package:aranduapp/core/state/command.dart';
import 'package:aranduapp/ui/navbar/view/navbar_view.dart';
import 'package:async/async.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:local_auth/local_auth.dart';
import 'package:aranduapp/ui/login/service/login_service.dart';
import 'package:aranduapp/ui/login/model/login_request.dart';
Expand Down Expand Up @@ -30,14 +30,14 @@ class LoginViewModel extends ChangeNotifier {
return Result.error(Exception('Valores inválidos'));
}

await LoginService.login(
await GetIt.instance<LoginService>().login(
LoginRequest(emailController.text, passwordController.text));

return Result.value(null);
}

Future<Result<void>> validateToken() async {
await LoginService.validateToken();
await GetIt.instance<LoginService>().validateToken();

return Result.value(null);
}
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
get_it:
dependency: "direct main"
description:
name: get_it
sha256: f126a3e286b7f5b578bf436d5592968706c4c1de28a228b870ce375d9f743103
url: "https://pub.dev"
source: hosted
version: "8.0.3"
glob:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies:
mockito: ^5.4.4
build_runner: ^2.4.13
async: ^2.11.0
get_it: ^8.0.3


dev_dependencies:
Expand Down
14 changes: 7 additions & 7 deletions test/ui/login/view/login_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'package:aranduapp/ui/shared/text_password.dart';
import 'package:async/async.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get_it/get_it.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:provider/provider.dart';

@GenerateNiceMocks([MockSpec<LoginViewModel>(), MockSpec<Command0>()])
import 'login_view_test.mocks.dart';
Expand All @@ -19,7 +19,7 @@ void main() {
late MockCommand0 mockLoginCommand;
late MockCommand0 mockValidadeTokenCommand;

setUp(() {
setUp(() async {
mockViewModel = MockLoginViewModel();
when(mockViewModel.formKey).thenReturn(GlobalKey<FormState>());
when(mockViewModel.emailController).thenReturn(TextEditingController());
Expand All @@ -38,14 +38,14 @@ void main() {
when(mockValidadeTokenCommand.running).thenReturn(false);
when(mockValidadeTokenCommand.isError).thenReturn(false);
when(mockValidadeTokenCommand.isOk).thenReturn(false);

await GetIt.instance.reset();
GetIt.I.registerLazySingleton<LoginViewModel>(() => mockViewModel);
});

Widget createLoginScreen() {
return ChangeNotifierProvider<LoginViewModel>.value(
value: mockViewModel,
child: const MaterialApp(
home: LoginScreen(),
),
return const MaterialApp(
home: Login(),
);
}

Expand Down

0 comments on commit cc6097c

Please sign in to comment.