TF-46 Create object, builder for model and core module

This commit is contained in:
dab246
2021-08-26 17:03:04 +07:00
committed by Dat H. Pham
parent b70fc6edb8
commit 17bad5ec51
21 changed files with 203 additions and 12 deletions
@@ -8,6 +8,8 @@ class TextFieldBuilder {
TextInputAction? _textInputAction;
InputDecoration? _inputDecoration;
bool? _obscureText;
int? _maxLines = 1;
TextEditingController? _textController;
TextFieldBuilder key(Key key) {
_key = key;
@@ -39,13 +41,25 @@ class TextFieldBuilder {
return this;
}
TextFieldBuilder setText(String value) {
_textController = TextEditingController.fromValue(TextEditingValue(text: value));
return this;
}
TextFieldBuilder maxLines(int? value) {
_maxLines = value;
return this;
}
TextField build() {
return TextField(
key: _key ?? Key('TextFieldBuilder'),
onChanged: _onTextChange,
cursorColor: AppColor.primaryColor,
controller: _textController,
textInputAction: _textInputAction,
decoration: _inputDecoration,
maxLines: _maxLines,
style: _textStyle ?? TextStyle(color: AppColor.textFieldTextColor),
obscureText: _obscureText ?? false,
);
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
typedef OnTapActionClick = void Function();
class TextFormFieldBuilder {
Key? _key;
ValueChanged<String>? _onTextChange;
InputDecoration? _inputDecoration;
TextInputAction? _textInputAction;
TextStyle? _textStyle;
OnTapActionClick? _onTapActionClick;
void key(Key key) {
_key = key;
}
void onChange(ValueChanged<String> onChange) {
_onTextChange = onChange;
}
void textStyle(TextStyle style) {
_textStyle = style;
}
void textDecoration(InputDecoration inputDecoration) {
_inputDecoration = inputDecoration;
}
void textInputAction(TextInputAction inputAction) {
_textInputAction = inputAction;
}
void addOnTapActionClick(OnTapActionClick onTapActionClick) {
_onTapActionClick = onTapActionClick;
}
TextFormField build() {
return TextFormField(
key: _key ?? Key('text_form_field_builder'),
keyboardType: TextInputType.multiline,
maxLines: null,
onChanged: _onTextChange,
style: _textStyle,
decoration: _inputDecoration,
textInputAction: _textInputAction,
onTap: () {
if (_onTapActionClick != null) {
_onTapActionClick!();
}
},
);
}
}