Init home feature add presentation layer
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tmail_ui_user/features/home/presentation/home_controller.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/repository/credential_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/get_credential_interactor.dart';
|
||||
|
||||
class HomeBindings extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => CredentialRepositoryImpl(Get.find<SharedPreferences>()));
|
||||
Get.lazyPut<CredentialRepository>(() => Get.find<CredentialRepositoryImpl>());
|
||||
|
||||
Get.lazyPut(() => GetCredentialInteractor(Get.find<CredentialRepository>()));
|
||||
|
||||
Get.lazyPut(() => HomeController(
|
||||
Get.find<GetCredentialInteractor>(),
|
||||
Get.find<DynamicUrlInterceptors>(),
|
||||
Get.find<AuthorizationInterceptors>()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/get_credential_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/get_credential_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
|
||||
class HomeController extends GetxController {
|
||||
final GetCredentialInteractor _getCredentialInteractor;
|
||||
final DynamicUrlInterceptors _dynamicUrlInterceptors;
|
||||
final AuthorizationInterceptors _authorizationInterceptors;
|
||||
|
||||
HomeController(this._getCredentialInteractor, this._dynamicUrlInterceptors, this._authorizationInterceptors);
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
_getCredentialAction();
|
||||
}
|
||||
|
||||
void _getCredentialAction() async {
|
||||
await _getCredentialInteractor.execute()
|
||||
.then((response) => response.fold(
|
||||
(failure) => _goToLogin(),
|
||||
(success) => success is GetCredentialViewState ? _goToMailbox(success) : _goToLogin()));
|
||||
}
|
||||
|
||||
void _goToLogin() {
|
||||
Get.offNamed(AppRoutes.LOGIN);
|
||||
}
|
||||
|
||||
void _goToMailbox(GetCredentialViewState credentialViewState) {
|
||||
_dynamicUrlInterceptors.changeBaseUrl(credentialViewState.baseUrl.origin);
|
||||
_authorizationInterceptors.changeAuthorization(
|
||||
credentialViewState.userName.userName,
|
||||
credentialViewState.password.value,
|
||||
);
|
||||
Get.offNamed(AppRoutes.MAILBOX);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/home/presentation/home_controller.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
class HomeView extends GetWidget<HomeController> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.primaryColor,
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(AppLocalizations.of(context).initializing_data, style: TextStyle(color: Colors.white, fontSize: 17)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user