Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1 Cherry pick insert link dialog (#2426) #2791

Open
wants to merge 5 commits into
base: refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions core/lib/presentation/views/text/text_form_field_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/utils/direction_utils.dart';
import 'package:flutter/material.dart';

typedef OnValidator = String? Function(String? value);

class TextFormFieldBuilder extends StatefulWidget {

final ValueChanged<String>? onTextChange;
Expand All @@ -25,6 +27,7 @@ class TextFormFieldBuilder extends StatefulWidget {
final bool readOnly;
final MouseCursor? mouseCursor;
final List<String>? autofillHints;
final OnValidator? validator;

const TextFormFieldBuilder({
super.key,
Expand All @@ -49,6 +52,7 @@ class TextFormFieldBuilder extends StatefulWidget {
this.onTap,
this.onTextChange,
this.onTextSubmitted,
this.validator,
});

@override
Expand All @@ -75,6 +79,42 @@ class _TextFieldFormBuilderState extends State<TextFormFieldBuilder> {

@override
Widget build(BuildContext context) {
if (widget.validator != null) {
return TextFormField(
key: widget.key,
controller: _controller,
cursorColor: widget.cursorColor,
autocorrect: widget.autocorrect,
textInputAction: widget.textInputAction,
decoration: widget.decoration,
maxLines: widget.maxLines,
minLines: widget.minLines,
keyboardAppearance: widget.keyboardAppearance,
style: widget.textStyle,
obscureText: widget.obscureText,
keyboardType: widget.keyboardType,
autofocus: widget.autoFocus,
focusNode: widget.focusNode,
textDirection: _textDirection,
readOnly: widget.readOnly,
mouseCursor: widget.mouseCursor,
autofillHints: widget.autofillHints,
onChanged: (value) {
widget.onTextChange?.call(value);
if (value.isNotEmpty) {
final directionByText = DirectionUtils.getDirectionByEndsText(value);
if (directionByText != _textDirection) {
setState(() {
_textDirection = directionByText;
});
}
}
},
onFieldSubmitted: widget.onTextSubmitted,
onTap: widget.onTap,
validator: widget.validator,
);
}
return TextField(
key: widget.key,
controller: _controller,
Expand Down
22 changes: 22 additions & 0 deletions lib/features/composer/presentation/composer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import 'package:tmail_ui_user/features/composer/presentation/styles/composer_sty
import 'package:tmail_ui_user/features/composer/presentation/widgets/mobile/from_composer_bottom_sheet_builder.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/saving_message_dialog_view.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/sending_message_dialog_view.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/web/insert_link_dialog_widget.dart';
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
import 'package:tmail_ui_user/features/email/domain/state/get_email_content_state.dart';
import 'package:tmail_ui_user/features/email/domain/state/transform_html_email_content_state.dart';
Expand Down Expand Up @@ -2167,4 +2168,25 @@ class ComposerController extends BaseController with DragDropFileMixin {
ccRecipientState.value = isEnabled ? PrefixRecipientState.disabled : PrefixRecipientState.enabled;
bccRecipientState.value = isEnabled ? PrefixRecipientState.disabled : PrefixRecipientState.enabled;
}

void onEditLinkAction(
BuildContext context,
String? text,
String? url,
bool? isOpenNewTab,
String linkTagId
) async {
Get.dialog(
PointerInterceptor(
child: InsertLinkDialogWidget(
responsiveUtils: responsiveUtils,
editorController: richTextWebController?.editorController,
linkTagId: linkTagId,
displayText: text ?? url ?? '',
link: url ?? '',
openNewTab: isOpenNewTab ?? true,
)
)
);
}
}
3 changes: 3 additions & 0 deletions lib/features/composer/presentation/composer_view_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class ComposerView extends GetWidget<ComposerController> {
width: constraints.maxWidth,
height: constraints.maxHeight,
onDragEnter: controller.handleOnDragEnterHtmlEditorWeb,
onEditLink: (text, url, isOpenNewTab, linkTagId) => controller.onEditLinkAction(context, text, url, isOpenNewTab, linkTagId),
)),
),
),
Expand Down Expand Up @@ -432,6 +433,7 @@ class ComposerView extends GetWidget<ComposerController> {
width: constraints.maxWidth,
height: constraints.maxHeight,
onDragEnter: controller.handleOnDragEnterHtmlEditorWeb,
onEditLink: (text, url, isOpenNewTab, linkTagId) => controller.onEditLinkAction(context, text, url, isOpenNewTab, linkTagId),
);
}),
),
Expand Down Expand Up @@ -694,6 +696,7 @@ class ComposerView extends GetWidget<ComposerController> {
width: constraints.maxWidth,
height: constraints.maxHeight,
onDragEnter: controller.handleOnDragEnterHtmlEditorWeb,
onEditLink: (text, url, isOpenNewTab, linkTagId) => controller.onEditLinkAction(context, text, url, isOpenNewTab, linkTagId),
)),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:flutter/material.dart';

class InsertLinkDialogWidgetStyle {
static const double actionOverFlowButtonSpacing = 8.0;
static const double elevation = 10.0;
static const double widthRatio = 0.3;
static const double tittleToFieldSpace = 10.0;
static const double fieldToFieldSpace = 20.0;
static const double buttonRadius = 10.0;
static const double buttonHeight = 40.0;

static const int maxLines = 1;

static const TextStyle tittleStyle = TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.black
);
static const TextStyle fieldTitleStyle = TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14,
color: Colors.black
);
static const TextStyle textInputStyle = TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Colors.black
);
static const TextStyle hintTextStyle = TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: AppColor.colorHintSearchBar
);
static const TextStyle buttonCancelTextStyle = TextStyle(
color: AppColor.primaryColor,
fontSize: 17.0,
fontWeight: FontWeight.w500
);
static const TextStyle buttonInsertTextStyle = TextStyle(
color: Colors.white,
fontSize: 17.0,
fontWeight: FontWeight.w500
);

static const EdgeInsetsGeometry tittlePadding = EdgeInsets.symmetric(
vertical: 16,
horizontal: 16
);
static const EdgeInsetsGeometry contentPadding = EdgeInsets.symmetric(
horizontal: 16
);
static const EdgeInsetsGeometry actionsPadding = EdgeInsets.symmetric(
vertical: 8,
horizontal: 16
);
static const EdgeInsetsGeometry textInputContentPadding = EdgeInsets.symmetric(
horizontal: 12.0,
vertical: 10.0
);

static const ShapeBorder shape = RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15))
);
static const InputBorder border = OutlineInputBorder(
borderSide: BorderSide(
color: AppColor.colorInputBorderCreateMailbox,
width: 1.0
),
borderRadius: BorderRadius.all(Radius.circular(10.0))
);
static const InputBorder focusedBorder = OutlineInputBorder(
borderSide: BorderSide(
color: AppColor.primaryColor,
width: 1.0
),
borderRadius: BorderRadius.all(Radius.circular(10.0))
);

static const InputDecoration urlFieldDecoration = InputDecoration(
filled: true,
fillColor: Colors.white,
contentPadding: textInputContentPadding,
enabledBorder: border,
border: border,
focusedBorder: focusedBorder,
hintText: 'URL',
hintStyle: hintTextStyle,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
final double? width;
final double? height;
final VoidCallback? onDragEnter;
final OnEditLink? onEditLink;

const WebEditorView({
super.key,
Expand All @@ -47,6 +48,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
this.width,
this.height,
this.onDragEnter,
this.onEditLink,
});

@override
Expand All @@ -73,6 +75,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
width: width,
height: height,
onDragEnter: onDragEnter,
onEditLink: onEditLink,
);
case EmailActionType.editDraft:
case EmailActionType.editSendingEmail:
Expand All @@ -98,6 +101,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
width: width,
height: height,
onDragEnter: onDragEnter,
onEditLink: onEditLink,
),
(success) {
if (success is GetEmailContentLoading) {
Expand All @@ -123,6 +127,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
width: width,
height: height,
onDragEnter: onDragEnter,
onEditLink: onEditLink,
);
}
}
Expand Down Expand Up @@ -155,6 +160,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
width: width,
height: height,
onDragEnter: onDragEnter,
onEditLink: onEditLink,
);
},
(success) {
Expand Down Expand Up @@ -183,6 +189,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
width: width,
height: height,
onDragEnter: onDragEnter,
onEditLink: onEditLink,
);
}
}
Expand All @@ -202,6 +209,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
width: width,
height: height,
onDragEnter: onDragEnter,
onEditLink: onEditLink,
);
}
}
Expand Down
Loading
Loading