TF-138 Add domain layer for search mail with text pattern

This commit is contained in:
dab246
2021-10-26 13:17:12 +07:00
committed by Dat H. Pham
parent 03f5921025
commit 62d416c4a4
11 changed files with 254 additions and 4 deletions
+1
View File
@@ -25,6 +25,7 @@ export 'presentation/views/text/slogan_builder.dart';
export 'presentation/views/text/text_field_builder.dart';
export 'presentation/views/text/input_decoration_builder.dart';
export 'presentation/views/text/text_builder.dart';
export 'presentation/views/text/rich_text_builder.dart';
export 'presentation/views/responsive/responsive_widget.dart';
export 'presentation/views/list/tree_view.dart';
export 'presentation/views/button/button_builder.dart';
@@ -59,4 +59,7 @@ extension AppColor on Color {
static const toastWithActionBackgroundColor = Color(0xFF3F3F3F);
static const buttonActionToastWithActionColor = Color(0xFF7ADCF8);
static const backgroundCountAttachment = Color(0x681C1C1C);
static const bgStatusResultSearch = Color(0xFFF5F5F7);
static const bgWordSearch = Color(0xFFD7D6FC);
}
@@ -0,0 +1,69 @@
import 'package:flutter/material.dart';
class RichTextBuilder {
final String _textOrigin;
final String _wordToStyle;
final TextStyle _styleOrigin;
final TextStyle _styleWord;
Key? _key;
int? _maxLines;
TextOverflow? _overflow;
RichTextBuilder(
this._textOrigin,
this._wordToStyle,
this._styleOrigin,
this._styleWord,
);
void key(Key key) {
_key = key;
}
void maxLines(int maxLines) {
_maxLines = maxLines;
}
void setOverflow(TextOverflow textOverflow) {
_overflow = textOverflow;
}
RichText build() {
return RichText(
key: _key,
maxLines: _maxLines ?? 1,
overflow: _overflow ?? TextOverflow.ellipsis,
text: TextSpan(
style: _styleOrigin,
children: _getSpans(_textOrigin, _wordToStyle, _styleWord)));
}
List<TextSpan> _getSpans(String text, String matchWord, TextStyle style) {
List<TextSpan> spans = [];
int spanBoundary = 0;
do {
// look for the next match
final startIndex = text.toLowerCase().indexOf(matchWord.toLowerCase(), spanBoundary);
// if no more matches then add the rest of the string without style
if (startIndex == -1) {
spans.add(TextSpan(text: text.substring(spanBoundary)));
return spans;
}
// add any unStyled text before the next match
if (startIndex > spanBoundary) {
spans.add(TextSpan(text: text.substring(spanBoundary, startIndex)));
}
// style the matched text
final endIndex = startIndex + matchWord.length;
final spanText = text.substring(startIndex, endIndex);
spans.add(TextSpan(text: spanText, style: style));
// mark the boundary to start the next search from
spanBoundary = endIndex;
// continue until there are no more matches
} while (spanBoundary < text.length);
return spans;
}
}
@@ -1,9 +1,12 @@
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:flutter/material.dart';
typedef OnOpenSearchMailActionClick = void Function();
class TextFieldBuilder {
Key? _key;
ValueChanged<String>? _onTextChange;
ValueChanged<String>? _onTextSubmitted;
TextStyle? _textStyle;
TextInputAction? _textInputAction;
InputDecoration? _inputDecoration;
@@ -11,6 +14,9 @@ class TextFieldBuilder {
int? _maxLines = 1;
TextEditingController? _textController;
TextInputType? _keyboardType;
Color? _cursorColor;
bool? _autoFocus;
FocusNode? _focusNode;
void key(Key key) {
_key = key;
@@ -20,6 +26,10 @@ class TextFieldBuilder {
_onTextChange = onChange;
}
void onSubmitted(ValueChanged<String> onSubmitted) {
_onTextSubmitted = onSubmitted;
}
void textStyle(TextStyle style) {
_textStyle = style;
}
@@ -40,7 +50,7 @@ class TextFieldBuilder {
_textController = TextEditingController.fromValue(TextEditingValue(text: value));
}
void addController(TextEditingController textEditingController) {
void addController(TextEditingController? textEditingController) {
_textController = textEditingController;
}
@@ -52,11 +62,23 @@ class TextFieldBuilder {
_keyboardType = value;
}
void cursorColor(Color? color) {
_cursorColor = color;
}
void autoFocus(bool autoFocus) {
_autoFocus = autoFocus;
}
void addFocusNode(FocusNode? focusNode) {
_focusNode = focusNode;
}
TextField build() {
return TextField(
key: _key ?? Key('TextFieldBuilder'),
onChanged: _onTextChange,
cursorColor: AppColor.primaryColor,
cursorColor: _cursorColor ?? AppColor.primaryColor,
controller: _textController,
autocorrect: false,
textInputAction: _textInputAction,
@@ -66,6 +88,9 @@ class TextFieldBuilder {
style: _textStyle ?? TextStyle(color: AppColor.textFieldTextColor),
obscureText: _obscureText ?? false,
keyboardType: _keyboardType,
onSubmitted: _onTextSubmitted,
autofocus: _autoFocus ?? false,
focusNode: _focusNode,
);
}
}