|
| 1 | +import 'package:flutter/services.dart'; |
| 2 | +import 'package:flutter/widgets.dart'; |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +class GFTextField extends StatefulWidget { |
| 8 | + |
| 9 | + GFTextField({ |
| 10 | + Key key, |
| 11 | + this.controller, |
| 12 | + String initialValue, |
| 13 | + FocusNode focusNode, |
| 14 | + InputDecoration decoration = const InputDecoration(), |
| 15 | + TextInputType keyboardType, |
| 16 | + TextCapitalization textCapitalization = TextCapitalization.none, |
| 17 | + TextInputAction textInputAction, |
| 18 | + TextStyle style, |
| 19 | + StrutStyle strutStyle, |
| 20 | + TextDirection textDirection, |
| 21 | + TextAlign textAlign = TextAlign.start, |
| 22 | + TextAlignVertical textAlignVertical, |
| 23 | + bool autofocus = false, |
| 24 | + bool readOnly = false, |
| 25 | + ToolbarOptions toolbarOptions, |
| 26 | + bool showCursor, |
| 27 | + String obscuringCharacter = '•', |
| 28 | + bool obscureText = false, |
| 29 | + bool autocorrect = true, |
| 30 | + SmartDashesType smartDashesType, |
| 31 | + SmartQuotesType smartQuotesType, |
| 32 | + bool enableSuggestions = true, |
| 33 | + bool autovalidate = false, |
| 34 | + bool maxLengthEnforced = true, |
| 35 | + int maxLines = 1, |
| 36 | + int minLines, |
| 37 | + bool expands = false, |
| 38 | + int maxLength, |
| 39 | + ValueChanged<String> onChanged, |
| 40 | + GestureTapCallback onTap, |
| 41 | + VoidCallback onEditingComplete, |
| 42 | + ValueChanged<String> onFieldSubmitted, |
| 43 | + FormFieldSetter<String> onSaved, |
| 44 | + FormFieldValidator<String> validator, |
| 45 | + List<TextInputFormatter> inputFormatters, |
| 46 | + bool enabled, |
| 47 | + double cursorWidth = 2.0, |
| 48 | + double cursorHeight, |
| 49 | + Radius cursorRadius, |
| 50 | + Color cursorColor, |
| 51 | + Brightness keyboardAppearance, |
| 52 | + EdgeInsets scrollPadding = const EdgeInsets.all(20.0), |
| 53 | + bool enableInteractiveSelection = true, |
| 54 | + InputCounterWidgetBuilder buildCounter, |
| 55 | + ScrollPhysics scrollPhysics, |
| 56 | + Iterable<String> autofillHints, |
| 57 | + AutovalidateMode autovalidateMode, |
| 58 | + }) : assert(initialValue == null || controller == null), |
| 59 | + assert(textAlign != null), |
| 60 | + assert(autofocus != null), |
| 61 | + assert(readOnly != null), |
| 62 | + assert(obscuringCharacter != null && obscuringCharacter.length == 1), |
| 63 | + assert(obscureText != null), |
| 64 | + assert(autocorrect != null), |
| 65 | + assert(enableSuggestions != null), |
| 66 | + assert(autovalidate != null), |
| 67 | + assert( |
| 68 | + autovalidate == false || |
| 69 | + autovalidate == true && autovalidateMode == null, |
| 70 | + 'autovalidate and autovalidateMode should not be used together.' |
| 71 | + ), |
| 72 | + assert(maxLengthEnforced != null), |
| 73 | + assert(scrollPadding != null), |
| 74 | + assert(maxLines == null || maxLines > 0), |
| 75 | + assert(minLines == null || minLines > 0), |
| 76 | + assert( |
| 77 | + (maxLines == null) || (minLines == null) || (maxLines >= minLines), |
| 78 | + "minLines can't be greater than maxLines", |
| 79 | + ), |
| 80 | + assert(expands != null), |
| 81 | + assert( |
| 82 | + !expands || (maxLines == null && minLines == null), |
| 83 | + 'minLines and maxLines must be null when expands is true.', |
| 84 | + ), |
| 85 | + assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), |
| 86 | + assert(maxLength == null || maxLength > 0), |
| 87 | + assert(enableInteractiveSelection != null), |
| 88 | + super( |
| 89 | + key: key, |
| 90 | + initialValue: controller != null ? controller.text : (initialValue ?? ''), |
| 91 | + onSaved: onSaved, |
| 92 | + validator: validator, |
| 93 | + enabled: enabled ?? decoration?.enabled ?? true, |
| 94 | + autovalidateMode: autovalidate |
| 95 | + ? AutovalidateMode.always |
| 96 | + : (autovalidateMode ?? AutovalidateMode.disabled), |
| 97 | + builder: (FormFieldState<String> field) { |
| 98 | + final _TextFormFieldState state = field as _TextFormFieldState; |
| 99 | + final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration()) |
| 100 | + .applyDefaults(Theme.of(field.context).inputDecorationTheme);}); |
| 101 | + @override |
| 102 | + _GFTextFieldState createState() => _GFTextFieldState(); |
| 103 | +} |
| 104 | + |
| 105 | +class _GFTextFieldState extends State<GFTextField> { |
| 106 | + @override |
| 107 | + Widget build(BuildContext context) { |
| 108 | + return Container( |
| 109 | + child: TextFormField(), |
| 110 | + ); |
| 111 | + } |
| 112 | +} |
0 commit comments