Skip to content

Commit 731f41b

Browse files
authored
Merge pull request #84 from lcsvcn/main
Added maxLength to fields
2 parents cc019a0 + feab384 commit 731f41b

File tree

5 files changed

+28
-39
lines changed

5 files changed

+28
-39
lines changed

example/lib/pages/text_input_dialog_page.dart

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class TextInputDialogPage extends ConsumerWidget {
5757
textFields: const [
5858
DialogTextField(
5959
hintText: 'hintText',
60+
maxLenght: 24,
6061
),
6162
],
6263
title: 'Hello',
@@ -73,14 +74,11 @@ class TextInputDialogPage extends ConsumerWidget {
7374
textFields: [
7475
DialogTextField(
7576
hintText: 'hintText',
76-
validator: (value) =>
77-
value!.isEmpty ? 'Input more than one character' : null,
77+
validator: (value) => value!.isEmpty ? 'Input more than one character' : null,
7878
),
7979
DialogTextField(
8080
hintText: 'hintText',
81-
validator: (value) => value!.length < 2
82-
? 'Input more than two characters'
83-
: null,
81+
validator: (value) => value!.length < 2 ? 'Input more than two characters' : null,
8482
),
8583
],
8684
title: 'Hello',
@@ -97,14 +95,11 @@ class TextInputDialogPage extends ConsumerWidget {
9795
textFields: [
9896
DialogTextField(
9997
hintText: 'hintText',
100-
validator: (value) =>
101-
value!.isEmpty ? 'Input more than one character' : null,
98+
validator: (value) => value!.isEmpty ? 'Input more than one character' : null,
10299
),
103100
DialogTextField(
104101
hintText: 'hintText',
105-
validator: (value) => value!.length < 2
106-
? 'Input more than two characters'
107-
: null,
102+
validator: (value) => value!.length < 2 ? 'Input more than two characters' : null,
108103
),
109104
],
110105
title: 'Hello',
@@ -166,12 +161,8 @@ class TextInputDialogPage extends ConsumerWidget {
166161
hintText: 'Start with "F"',
167162
retryTitle: 'Incorrect',
168163
retryMessage: 'Retry?',
169-
retryOkLabel: ref
170-
.watch(adaptiveStyleProvider)
171-
.effectiveStyle(theme)
172-
.isMaterial(theme)
173-
? 'RETRY'
174-
: 'Retry',
164+
retryOkLabel:
165+
ref.watch(adaptiveStyleProvider).effectiveStyle(theme).isMaterial(theme) ? 'RETRY' : 'Retry',
175166
);
176167
logger.info('ok: $ok');
177168
if (!ok) {

lib/src/text_input_dialog/ios_text_input_dialog.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class _IOSTextInputDialogState extends State<IOSTextInputDialog> {
131131
placeholder: field.hintText,
132132
obscureText: field.obscureText,
133133
keyboardType: field.keyboardType,
134+
maxLength: field.maxLenght,
134135
minLines: field.minLines,
135136
maxLines: field.maxLines,
136137
autocorrect: field.autocorrect,

lib/src/text_input_dialog/macos_text_input_dialog.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class _MacOSTextInputDialogState extends State<MacOSTextInputDialog> {
141141
keyboardType: field.keyboardType,
142142
minLines: field.minLines,
143143
maxLines: field.maxLines,
144+
maxLength: field.maxLenght,
144145
autocorrect: field.autocorrect,
145146
prefix:
146147
prefixText == null ? null : Text(prefixText),

lib/src/text_input_dialog/material_text_input_dialog.dart

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class MaterialTextInputDialog extends StatefulWidget {
2020
this.autoSubmit = false,
2121
});
2222
@override
23-
_MaterialTextInputDialogState createState() =>
24-
_MaterialTextInputDialogState();
23+
_MaterialTextInputDialogState createState() => _MaterialTextInputDialogState();
2524

2625
final List<DialogTextField> textFields;
2726
final String? title;
@@ -38,9 +37,8 @@ class MaterialTextInputDialog extends StatefulWidget {
3837
}
3938

4039
class _MaterialTextInputDialogState extends State<MaterialTextInputDialog> {
41-
late final List<TextEditingController> _textControllers = widget.textFields
42-
.map((tf) => TextEditingController(text: tf.initialText))
43-
.toList();
40+
late final List<TextEditingController> _textControllers =
41+
widget.textFields.map((tf) => TextEditingController(text: tf.initialText)).toList();
4442
final _formKey = GlobalKey<FormState>();
4543
var _autovalidateMode = AutovalidateMode.disabled;
4644

@@ -85,8 +83,7 @@ class _MaterialTextInputDialogState extends State<MaterialTextInputDialog> {
8583
final cancelLabel = widget.cancelLabel;
8684
final okLabel = widget.okLabel;
8785
final okText = Text(
88-
(widget.fullyCapitalized ? okLabel?.toUpperCase() : okLabel) ??
89-
MaterialLocalizations.of(context).okButtonLabel,
86+
(widget.fullyCapitalized ? okLabel?.toUpperCase() : okLabel) ?? MaterialLocalizations.of(context).okButtonLabel,
9087
style: TextStyle(
9188
color: widget.isDestructiveAction ? colorScheme.error : null,
9289
),
@@ -114,26 +111,25 @@ class _MaterialTextInputDialogState extends State<MaterialTextInputDialog> {
114111
),
115112
..._textControllers.mapIndexed((i, c) {
116113
final isLast = widget.textFields.length == i + 1;
117-
final textField = widget.textFields[i];
114+
final field = widget.textFields[i];
118115
return TextFormField(
119116
controller: c,
120117
autofocus: i == 0,
121-
obscureText: textField.obscureText,
122-
keyboardType: textField.keyboardType,
123-
minLines: textField.minLines,
124-
maxLines: textField.maxLines,
125-
autocorrect: textField.autocorrect,
118+
obscureText: field.obscureText,
119+
keyboardType: field.keyboardType,
120+
minLines: field.minLines,
121+
maxLines: field.maxLines,
122+
maxLength: field.maxLenght,
123+
autocorrect: field.autocorrect,
126124
decoration: InputDecoration(
127-
hintText: textField.hintText,
128-
prefixText: textField.prefixText,
129-
suffixText: textField.suffixText,
125+
hintText: field.hintText,
126+
prefixText: field.prefixText,
127+
suffixText: field.suffixText,
130128
),
131-
validator: textField.validator,
129+
validator: field.validator,
132130
autovalidateMode: _autovalidateMode,
133131
textInputAction: isLast ? null : TextInputAction.next,
134-
onFieldSubmitted: isLast && widget.autoSubmit
135-
? (_) => submitIfValid()
136-
: null,
132+
onFieldSubmitted: isLast && widget.autoSubmit ? (_) => submitIfValid() : null,
137133
);
138134
})
139135
],
@@ -142,9 +138,7 @@ class _MaterialTextInputDialogState extends State<MaterialTextInputDialog> {
142138
TextButton(
143139
onPressed: cancel,
144140
child: Text(
145-
(widget.fullyCapitalized
146-
? cancelLabel?.toUpperCase()
147-
: cancelLabel) ??
141+
(widget.fullyCapitalized ? cancelLabel?.toUpperCase() : cancelLabel) ??
148142
MaterialLocalizations.of(context).cancelButtonLabel,
149143
),
150144
),

lib/src/text_input_dialog/show_text_input_dialog.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class DialogTextField {
122122
this.suffixText,
123123
this.minLines,
124124
this.maxLines = 1,
125+
this.maxLenght,
125126
this.autocorrect = true,
126127
});
127128
final String? initialText;
@@ -133,5 +134,6 @@ class DialogTextField {
133134
final String? suffixText;
134135
final int? minLines;
135136
final int maxLines;
137+
final int? maxLenght;
136138
final bool autocorrect;
137139
}

0 commit comments

Comments
 (0)