Skip to content

Commit

Permalink
TF-2046 Use controller cached in GetWidget instead of using Get.fin…
Browse files Browse the repository at this point in the history
…d<LoginController>()
  • Loading branch information
dab246 authored and hoangdat committed Jul 20, 2023
1 parent 466784a commit 4403e28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
19 changes: 9 additions & 10 deletions lib/features/login/presentation/base_login_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
abstract class BaseLoginView extends GetWidget<LoginController> {
BaseLoginView({Key? key}) : super(key: key);

final loginController = Get.find<LoginController>();
final responsiveUtils = Get.find<ResponsiveUtils>();
final imagePaths = Get.find<ImagePaths>();

Expand Down Expand Up @@ -58,9 +57,9 @@ abstract class BaseLoginView extends GetWidget<LoginController> {
}
},
(success) {
if (loginController.loginFormType.value == LoginFormType.credentialForm) {
if (controller.loginFormType.value == LoginFormType.credentialForm) {
return AppLocalizations.of(context).loginInputCredentialMessage;
} else if (loginController.loginFormType.value == LoginFormType.ssoForm) {
} else if (controller.loginFormType.value == LoginFormType.ssoForm) {
return AppLocalizations.of(context).loginInputSSOMessage;
}
return AppLocalizations.of(context).loginInputUrlMessage;
Expand Down Expand Up @@ -107,7 +106,7 @@ abstract class BaseLoginView extends GetWidget<LoginController> {
side: const BorderSide(width: 0, color: AppColor.primaryColor)
))
),
onPressed: loginController.handleLoginPressed,
onPressed: controller.handleLoginPressed,
child: Text(
AppLocalizations.of(context).signIn,
style: const TextStyle(fontSize: 16, color: Colors.white)
Expand All @@ -132,8 +131,8 @@ abstract class BaseLoginView extends GetWidget<LoginController> {
padding: const EdgeInsets.only(bottom: 24, right: 24, left: 24),
child: TypeAheadFormFieldBuilder<RecentLoginUsername>(
key: const Key('login_username_input'),
controller: loginController.usernameInputController,
onTextChange: loginController.setUserNameText,
controller: controller.usernameInputController,
onTextChange: controller.setUserNameText,
textInputAction: TextInputAction.next,
autocorrect: false,
autofillHints: const [AutofillHints.email],
Expand All @@ -143,10 +142,10 @@ abstract class BaseLoginView extends GetWidget<LoginController> {
..setHintText(AppLocalizations.of(context).email))
.build(),
debounceDuration: const Duration(milliseconds: 300),
suggestionsCallback: loginController.getAllRecentLoginUsernameAction,
suggestionsCallback: controller.getAllRecentLoginUsernameAction,
itemBuilder: (context, loginUsername) => RecentItemTileWidget(loginUsername, imagePath: imagePaths),
onSuggestionSelected: (recentUsername) {
loginController.setUsername(recentUsername.username);
controller.setUsername(recentUsername.username);
passFocusNode.requestFocus();
},
suggestionsBoxDecoration: const SuggestionsBoxDecoration(borderRadius: BorderRadius.all(Radius.circular(14))),
Expand All @@ -168,11 +167,11 @@ abstract class BaseLoginView extends GetWidget<LoginController> {
autocorrect: false,
autofillHints: [AutofillHints.password]
)
..setOnSubmitted((value) => loginController.handleLoginPressed())
..setOnSubmitted((value) => controller.handleLoginPressed())
..passwordInput(true)
..key(const Key('login_password_input'))
..obscureText(true)
..onChange(loginController.setPasswordText)
..onChange(controller.setPasswordText)
..textInputAction(TextInputAction.done)
..hintText(AppLocalizations.of(context).password)
..setFocusNode(passFocusNode))
Expand Down
20 changes: 10 additions & 10 deletions lib/features/login/presentation/login_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class LoginView extends BaseLoginView {
scrollDirection: Axis.vertical,
child: _buildCenterForm(context))),
Obx(() {
if (loginController.loginFormType.value == LoginFormType.credentialForm
|| loginController.loginFormType.value == LoginFormType.ssoForm) {
if (controller.loginFormType.value == LoginFormType.credentialForm
|| controller.loginFormType.value == LoginFormType.ssoForm) {
return _buildBackButton(context);
}
return const SizedBox.shrink();
Expand All @@ -42,8 +42,8 @@ class LoginView extends BaseLoginView {
: Stack(children: [
_buildCenterForm(context),
Obx(() {
if (loginController.loginFormType.value == LoginFormType.credentialForm
|| loginController.loginFormType.value == LoginFormType.ssoForm) {
if (controller.loginFormType.value == LoginFormType.credentialForm
|| controller.loginFormType.value == LoginFormType.ssoForm) {
return _buildBackButton(context);
}
return const SizedBox.shrink();
Expand Down Expand Up @@ -72,7 +72,7 @@ class LoginView extends BaseLoginView {
style: const TextStyle(fontSize: 32, color: AppColor.colorNameEmail, fontWeight: FontWeight.w900)
)
),
Obx(() => buildLoginMessage(context, loginController.viewState.value)),
Obx(() => buildLoginMessage(context, controller.viewState.value)),
Obx(() {
switch (controller.loginFormType.value) {
case LoginFormType.baseUrlForm:
Expand Down Expand Up @@ -114,7 +114,7 @@ class LoginView extends BaseLoginView {
return Padding(
padding: const EdgeInsets.only(right: 24, left: 24, bottom: 24),
child: TypeAheadFormFieldBuilder<RecentLoginUrl>(
controller: loginController.urlInputController,
controller: controller.urlInputController,
textInputAction: TextInputAction.next,
keyboardType: TextInputType.url,
onTextSubmitted: (value) => controller.handleNextInUrlInputFormPress(),
Expand All @@ -124,8 +124,8 @@ class LoginView extends BaseLoginView {
.build(),
debounceDuration: const Duration(milliseconds: 300),
suggestionsCallback: (pattern) async {
loginController.formatUrl(pattern);
return loginController.getAllRecentLoginUrlAction(pattern);
controller.formatUrl(pattern);
return controller.getAllRecentLoginUrlAction(pattern);
},
itemBuilder: (context, loginUrl) => RecentItemTileWidget(loginUrl, imagePath: imagePaths),
onSuggestionSelected: (loginUrl) => controller.formatUrl(loginUrl.url),
Expand Down Expand Up @@ -165,7 +165,7 @@ class LoginView extends BaseLoginView {
style: const TextStyle(fontSize: 16, color: Colors.white)
),
onPressed: () {
loginController.handleNextInUrlInputFormPress();
controller.handleNextInUrlInputFormPress();
}
)
);
Expand All @@ -188,7 +188,7 @@ class LoginView extends BaseLoginView {
}

Widget _buildLoadingProgress(BuildContext context) {
return Obx(() => loginController.viewState.value.fold(
return Obx(() => controller.viewState.value.fold(
(failure) {
switch (controller.loginFormType.value) {
case LoginFormType.baseUrlForm:
Expand Down
8 changes: 4 additions & 4 deletions lib/features/login/presentation/login_view_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LoginView extends BaseLoginView {
style: const TextStyle(fontSize: 32, color: AppColor.colorNameEmail, fontWeight: FontWeight.w900)
)
),
Obx(() => buildLoginMessage(context, loginController.viewState.value)),
Obx(() => buildLoginMessage(context, controller.viewState.value)),
Obx(() {
switch (controller.loginFormType.value) {
case LoginFormType.credentialForm:
Expand Down Expand Up @@ -179,7 +179,7 @@ class LoginView extends BaseLoginView {
style: const TextStyle(fontSize: 32, color: AppColor.colorNameEmail, fontWeight: FontWeight.w900)
)
),
Obx(() => buildLoginMessage(context, loginController.viewState.value)),
Obx(() => buildLoginMessage(context, controller.viewState.value)),
Obx(() {
switch (controller.loginFormType.value) {
case LoginFormType.credentialForm:
Expand Down Expand Up @@ -251,14 +251,14 @@ class LoginView extends BaseLoginView {
style: const TextStyle(fontSize: 16, color: Colors.white)
),
onPressed: () {
loginController.handleSSOPressed();
controller.handleSSOPressed();
}
)
);
}

Widget _buildLoadingProgress(BuildContext context) {
return Obx(() => loginController.viewState.value.fold(
return Obx(() => controller.viewState.value.fold(
(failure) {
switch (controller.loginFormType.value) {
case LoginFormType.baseUrlForm:
Expand Down

0 comments on commit 4403e28

Please sign in to comment.