Skip to content

Commit 8b28198

Browse files
committed
refactor: Add font size & clear button optional support for textfield
1 parent 2851341 commit 8b28198

File tree

1 file changed

+78
-59
lines changed

1 file changed

+78
-59
lines changed

ui/lib/src/text_field.dart

Lines changed: 78 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@ import 'package:flutter_svg/flutter_svg.dart';
33
import 'package:mxc_ui/mxc_ui.dart';
44

55
class MxcTextField extends FormField<String> {
6-
MxcTextField(
7-
{required Key? key,
8-
String? label,
9-
required TextEditingController this.controller,
10-
String? hint,
11-
FormFieldValidator<String>? validator,
12-
TextInputAction? action,
13-
bool readOnly = false,
14-
MxcTextFieldButton? suffixButton,
15-
double width = double.infinity,
16-
FocusNode? focusNode,
17-
TextInputType? keyboardType,
18-
String? suffixText,
19-
bool obscure = false,
20-
AutovalidateMode? autovalidateMode,
21-
String? followText,
22-
String? errorText,
23-
ValueChanged<String>? onChanged,
24-
final ValueChanged<bool>? onFocused,
25-
Function(PointerDownEvent)? onTapOutside,
26-
bool autoFocus = false,
27-
bool hasClearButton = true})
28-
: super(
6+
MxcTextField({
7+
required Key? key,
8+
String? label,
9+
required TextEditingController this.controller,
10+
String? hint,
11+
FormFieldValidator<String>? validator,
12+
TextInputAction? action,
13+
bool readOnly = false,
14+
MxcTextFieldButton? suffixButton,
15+
double width = double.infinity,
16+
FocusNode? focusNode,
17+
TextInputType? keyboardType,
18+
String? suffixText,
19+
bool obscure = false,
20+
AutovalidateMode? autovalidateMode,
21+
String? followText,
22+
String? errorText,
23+
ValueChanged<String>? onChanged,
24+
final ValueChanged<bool>? onFocused,
25+
Function(PointerDownEvent)? onTapOutside,
26+
bool autoFocus = false,
27+
bool hasClearButton = true,
28+
double? fontSize,
29+
}) : super(
2930
key: key,
3031
initialValue: controller.text,
3132
validator: validator,
@@ -51,6 +52,7 @@ class MxcTextField extends FormField<String> {
5152
onTapOutside: onTapOutside,
5253
autoFocus: autoFocus,
5354
hasClearButton: hasClearButton,
55+
fontSize: fontSize,
5456
);
5557
},
5658
);
@@ -68,6 +70,7 @@ class MxcTextField extends FormField<String> {
6870
String? suffixText,
6971
bool obscure = false,
7072
String? followText,
73+
double? fontSize,
7174
}) : controller = null,
7275
super(
7376
key: key,
@@ -83,6 +86,7 @@ class MxcTextField extends FormField<String> {
8386
suffixText: suffixText,
8487
width: width,
8588
followText: followText,
89+
fontSize: fontSize,
8690
),
8791
);
8892

@@ -96,6 +100,7 @@ class MxcTextField extends FormField<String> {
96100
FocusNode? focusNode,
97101
String? suffixText,
98102
bool obscure = false,
103+
double? fontSize,
99104
}) : controller = null,
100105
super(
101106
key: key,
@@ -109,6 +114,7 @@ class MxcTextField extends FormField<String> {
109114
obscure: obscure,
110115
suffixText: suffixText,
111116
width: width,
117+
fontSize: fontSize,
112118
),
113119
);
114120

@@ -129,6 +135,8 @@ class MxcTextField extends FormField<String> {
129135
MxcTextFieldButton? suffixButton,
130136
bool expands = false,
131137
int? minLines,
138+
bool? hasClearButton,
139+
double? fontSize,
132140
}) : super(
133141
key: key,
134142
initialValue: controller.text,
@@ -154,6 +162,8 @@ class MxcTextField extends FormField<String> {
154162
focusNode: focusNode,
155163
expands: expands,
156164
minLines: minLines,
165+
hasClearButton: hasClearButton ?? true,
166+
fontSize: fontSize,
157167
);
158168
},
159169
);
@@ -170,6 +180,7 @@ class MxcTextField extends FormField<String> {
170180
TextInputAction? action,
171181
ValueChanged<String>? onChanged,
172182
Widget? prefix,
183+
double? fontSize,
173184
}) : super(
174185
key: key,
175186
initialValue: controller.text,
@@ -193,6 +204,7 @@ class MxcTextField extends FormField<String> {
193204
borderRadius: const BorderRadius.all(Radius.circular(100)),
194205
onChanged: onChanged,
195206
prefix: prefix,
207+
fontSize: fontSize,
196208
);
197209
},
198210
);
@@ -264,41 +276,43 @@ class _MxcNonFormTextField extends StatefulWidget {
264276
this.hasClearButton = true,
265277
this.expands = false,
266278
this.minLines,
279+
this.fontSize,
267280
}) : _controller = controller,
268281
_initialValue = null,
269282
disabled = false,
270283
super(key: key);
271284

272-
const _MxcNonFormTextField.viewOnly(
273-
{Key? key,
274-
required this.label,
275-
required String text,
276-
this.hint,
277-
this.action,
278-
this.suffixButton,
279-
this.width = double.infinity,
280-
this.focusNode,
281-
this.keyboardType,
282-
this.suffixText,
283-
this.obscure = false,
284-
this.disabled = false,
285-
this.followText,
286-
this.useAnimation = true,
287-
this.backgroundColor,
288-
this.margin,
289-
this.padding,
290-
this.borderRadius,
291-
this.borderUnFocusColor,
292-
this.borderFocusColor,
293-
this.prefix,
294-
this.onFocused,
295-
this.onTapOutside,
296-
this.textColor,
297-
this.autoFocus = false,
298-
this.hasClearButton = true,
299-
this.expands = false,
300-
this.minLines})
301-
: _initialValue = text,
285+
const _MxcNonFormTextField.viewOnly({
286+
Key? key,
287+
required this.label,
288+
required String text,
289+
this.hint,
290+
this.action,
291+
this.suffixButton,
292+
this.width = double.infinity,
293+
this.focusNode,
294+
this.keyboardType,
295+
this.suffixText,
296+
this.obscure = false,
297+
this.disabled = false,
298+
this.followText,
299+
this.useAnimation = true,
300+
this.backgroundColor,
301+
this.margin,
302+
this.padding,
303+
this.borderRadius,
304+
this.borderUnFocusColor,
305+
this.borderFocusColor,
306+
this.prefix,
307+
this.onFocused,
308+
this.onTapOutside,
309+
this.textColor,
310+
this.fontSize,
311+
this.autoFocus = false,
312+
this.hasClearButton = true,
313+
this.expands = false,
314+
this.minLines,
315+
}) : _initialValue = text,
302316
readOnly = true,
303317
_controller = null,
304318
maxLines = 1,
@@ -343,6 +357,7 @@ class _MxcNonFormTextField extends StatefulWidget {
343357
final Widget? prefix;
344358

345359
final Color? textColor;
360+
final double? fontSize;
346361

347362
@override
348363
State<_MxcNonFormTextField> createState() => _MxcNonFormTextFieldState();
@@ -481,20 +496,24 @@ class _MxcNonFormTextFieldState extends State<_MxcNonFormTextField> {
481496
? FontTheme.of(context).body1().copyWith(
482497
color: ColorsTheme.of(context)
483498
.backgroundDisabled,
499+
fontSize: widget.fontSize,
484500
)
485-
: FontTheme.of(context)
486-
.body1()
487-
.copyWith(color: widget.textColor),
501+
: FontTheme.of(context).body1().copyWith(
502+
color: widget.textColor,
503+
fontSize: widget.fontSize,
504+
),
488505
obscureText: widget.obscure,
489506
onChanged: widget.onChanged,
490507
onTapOutside: widget.onTapOutside,
491508
decoration: InputDecoration(
492509
isDense: true,
493510
floatingLabelBehavior: FloatingLabelBehavior.always,
494511
hintText: widget.hint,
495-
hintStyle: FontTheme.of(context)
496-
.subtitle1()
497-
.copyWith(color: ColorsTheme.of(context).grey1),
512+
hintStyle:
513+
FontTheme.of(context).subtitle1().copyWith(
514+
color: ColorsTheme.of(context).grey1,
515+
fontSize: widget.fontSize,
516+
),
498517
enabledBorder: InputBorder.none,
499518
focusedBorder: InputBorder.none,
500519
errorBorder: InputBorder.none,

0 commit comments

Comments
 (0)