TF-1074 Handle go to path /mailbox_creator

This commit is contained in:
dab246
2022-10-25 00:25:08 +07:00
committed by Dat H. Pham
parent daddeb78dc
commit 50bba630d5
9 changed files with 142 additions and 42 deletions
@@ -7,9 +7,7 @@ class MailboxCreatorBindings extends BaseBindings {
@override
void bindingsController() {
Get.lazyPut(() => MailboxCreatorController(
Get.find<VerifyNameInteractor>(),
));
Get.lazyPut(() => MailboxCreatorController(Get.find<VerifyNameInteractor>()));
}
@override
@@ -28,4 +26,8 @@ class MailboxCreatorBindings extends BaseBindings {
@override
void bindingsRepositoryImpl() {}
void dispose() {
Get.delete<MailboxCreatorController>();
}
}
@@ -20,6 +20,8 @@ import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/new_ma
import 'package:tmail_ui_user/main/routes/app_routes.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
typedef OnCreatedMailboxCallback = Function(NewMailboxArguments? arguments);
class MailboxCreatorController extends BaseController {
final VerifyNameInteractor _verifyNameInteractor;
@@ -27,27 +29,34 @@ class MailboxCreatorController extends BaseController {
final selectedMailbox = Rxn<PresentationMailbox>();
final newNameMailbox = Rxn<String>();
final nameInputFocusNode = FocusNode();
FocusNode? nameInputFocusNode;
MailboxCreatorArguments? arguments;
AccountId? accountId;
MailboxTree? folderMailboxTree;
MailboxTree? defaultMailboxTree;
OnCreatedMailboxCallback? onCreatedMailboxCallback;
VoidCallback? onDismissMailboxCreator;
List<String> listMailboxNameAsStringExist = <String>[];
MailboxCreatorController(
this._verifyNameInteractor,
);
MailboxCreatorController(this._verifyNameInteractor);
void setNewNameMailbox(String newName) => newNameMailbox.value = newName;
@override
void onInit() {
super.onInit();
nameInputFocusNode = FocusNode();
}
@override
void onReady() {
super.onReady();
final arguments = Get.arguments;
if (arguments is MailboxCreatorArguments) {
folderMailboxTree = arguments.folderMailboxTree;
defaultMailboxTree = arguments.defaultMailboxTree;
accountId = arguments.accountId;
if (arguments != null) {
folderMailboxTree = arguments!.folderMailboxTree;
defaultMailboxTree = arguments!.defaultMailboxTree;
accountId = arguments!.accountId;
_createListMailboxNameAsStringInMailboxLocation();
}
}
@@ -61,14 +70,14 @@ class MailboxCreatorController extends BaseController {
@override
void onClose() {
nameInputFocusNode.dispose();
nameInputFocusNode?.dispose();
super.onClose();
}
bool isCreateMailboxValidated(BuildContext context) {
final nameValidated = getErrorInputNameString(context);
if (!nameInputFocusNode.hasFocus && newNameMailbox.value == null) {
if (nameInputFocusNode?.hasFocus == false && newNameMailbox.value == null) {
return false;
}
@@ -109,14 +118,12 @@ class MailboxCreatorController extends BaseController {
listMailboxNameAsStringExist = [];
}
}
log('MailboxCreatorController::_createListMailboxNameAsStringInMailboxLocation(): ${listMailboxNameAsStringExist.toString()}');
}
String? getErrorInputNameString(BuildContext context) {
final nameMailbox = newNameMailbox.value;
if (!nameInputFocusNode.hasFocus && nameMailbox == null) {
if (nameInputFocusNode?.hasFocus == false && nameMailbox == null) {
return null;
}
@@ -178,17 +185,34 @@ class MailboxCreatorController extends BaseController {
void createNewMailbox(BuildContext context) {
FocusScope.of(context).unfocus();
final nameMailbox = newNameMailbox.value;
if (nameMailbox != null && nameMailbox.isNotEmpty) {
final newMailboxArguments = NewMailboxArguments(
MailboxName(nameMailbox),
mailboxLocation: selectedMailbox.value);
popBack(result: newMailboxArguments);
if (BuildUtils.isWeb) {
nameInputFocusNode?.dispose();
nameInputFocusNode = null;
onCreatedMailboxCallback?.call(newMailboxArguments);
} else {
popBack(result: newMailboxArguments);
}
}
}
void closeMailboxCreator(BuildContext context) {
FocusScope.of(context).unfocus();
popBack();
if (BuildUtils.isWeb) {
nameInputFocusNode?.dispose();
nameInputFocusNode = null;
onDismissMailboxCreator?.call();
} else {
popBack();
}
}
}
@@ -1,10 +1,16 @@
import 'package:core/core.dart';
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/presentation/utils/style_utils.dart';
import 'package:core/presentation/views/text/text_field_builder.dart';
import 'package:core/utils/build_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/extensions/presentation_mailbox_extension.dart';
import 'package:tmail_ui_user/features/mailbox_creator/presentation/mailbox_creator_controller.dart';
import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart';
import 'package:tmail_ui_user/features/mailbox_creator/presentation/widgets/app_bar_mailbox_creator_builder.dart';
import 'package:tmail_ui_user/features/mailbox_creator/presentation/widgets/create_mailbox_name_input_decoration_builder.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
@@ -15,7 +21,24 @@ class MailboxCreatorView extends GetWidget<MailboxCreatorController> {
final _imagePaths = Get.find<ImagePaths>();
final _responsiveUtils = Get.find<ResponsiveUtils>();
MailboxCreatorView({Key? key}) : super(key: key);
@override
final controller = Get.find<MailboxCreatorController>();
MailboxCreatorView({Key? key}) : super(key: key) {
controller.arguments = Get.arguments;
}
MailboxCreatorView.fromArguments(
MailboxCreatorArguments arguments, {
Key? key,
OnCreatedMailboxCallback? onCreatedMailboxCallback,
VoidCallback? onDismissCallback
}) : super(key: key) {
controller.arguments = arguments;
controller.onCreatedMailboxCallback = onCreatedMailboxCallback;
controller.onDismissMailboxCreator = onDismissCallback;
controller.onInit();
}
@override
Widget build(BuildContext context) {
@@ -95,7 +118,7 @@ class MailboxCreatorView extends GetWidget<MailboxCreatorController> {
..keyboardType(TextInputType.visiblePassword)
..cursorColor(AppColor.colorTextButton)
..maxLines(1)
..textStyle(TextStyle(
..textStyle(const TextStyle(
color: AppColor.colorNameEmail,
fontSize: 16,
overflow: CommonTextStyle.defaultTextOverFlow))