Skip to content

Commit 88275f4

Browse files
committed
Formatters & Validators #17
1 parent e088bd3 commit 88275f4

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed

lib/src/api/models/text_input_validator_model.dart

+172
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,178 @@ import '../mixins.dart';
77

88
part 'text_input_validator_model.g.dart';
99

10+
/// Represents an action to perform when the user presses the action button on
11+
/// the keyboard.
12+
enum TextInputActionC {
13+
/// Logical meaning: There is no relevant input action for the current input
14+
/// source, e.g., [TextField].
15+
///
16+
/// Android: Corresponds to Android's "IME_ACTION_NONE". The keyboard setup
17+
/// is decided by the OS. The keyboard will likely show a return key.
18+
///
19+
/// iOS: iOS does not have a keyboard return type of "none." It is
20+
/// inappropriate to choose this [TextInputAction] when running on iOS.
21+
none,
22+
23+
/// Logical meaning: Let the OS decide which action is most appropriate.
24+
///
25+
/// Android: Corresponds to Android's "IME_ACTION_UNSPECIFIED". The OS chooses
26+
/// which keyboard action to display. The decision will likely be a done
27+
/// button or a return key.
28+
///
29+
/// iOS: Corresponds to iOS's "UIReturnKeyDefault". The title displayed in
30+
/// the action button is "return".
31+
unspecified,
32+
33+
/// Logical meaning: The user is done providing input to a group of inputs
34+
/// (like a form). Some kind of finalization behavior should now take place.
35+
///
36+
/// Android: Corresponds to Android's "IME_ACTION_DONE". The OS displays a
37+
/// button that represents completion, e.g., a checkmark button.
38+
///
39+
/// iOS: Corresponds to iOS's "UIReturnKeyDone". The title displayed in the
40+
/// action button is "Done".
41+
done,
42+
43+
/// Logical meaning: The user has entered some text that represents a
44+
/// destination, e.g., a restaurant name. The "go" button is intended to take
45+
/// the user to a part of the app that corresponds to this destination.
46+
///
47+
/// Android: Corresponds to Android's "IME_ACTION_GO". The OS displays a
48+
/// button that represents taking "the user to the target of the text they
49+
/// typed", e.g., a right-facing arrow button.
50+
///
51+
/// iOS: Corresponds to iOS's "UIReturnKeyGo". The title displayed in the
52+
/// action button is "Go".
53+
go,
54+
55+
/// Logical meaning: Execute a search query.
56+
///
57+
/// Android: Corresponds to Android's "IME_ACTION_SEARCH". The OS displays a
58+
/// button that represents a search, e.g., a magnifying glass button.
59+
///
60+
/// iOS: Corresponds to iOS's "UIReturnKeySearch". The title displayed in the
61+
/// action button is "Search".
62+
search,
63+
64+
/// Logical meaning: Sends something that the user has composed, e.g., an
65+
/// email or a text message.
66+
///
67+
/// Android: Corresponds to Android's "IME_ACTION_SEND". The OS displays a
68+
/// button that represents sending something, e.g., a paper plane button.
69+
///
70+
/// iOS: Corresponds to iOS's "UIReturnKeySend". The title displayed in the
71+
/// action button is "Send".
72+
send,
73+
74+
/// Logical meaning: The user is done with the current input source and wants
75+
/// to move to the next one.
76+
///
77+
/// Moves the focus to the next focusable item in the same [FocusScope].
78+
///
79+
/// Android: Corresponds to Android's "IME_ACTION_NEXT". The OS displays a
80+
/// button that represents moving forward, e.g., a right-facing arrow button.
81+
///
82+
/// iOS: Corresponds to iOS's "UIReturnKeyNext". The title displayed in the
83+
/// action button is "Next".
84+
next,
85+
86+
/// Logical meaning: The user wishes to return to the previous input source
87+
/// in the group, e.g., a form with multiple [TextField]s.
88+
///
89+
/// Moves the focus to the previous focusable item in the same [FocusScope].
90+
///
91+
/// Android: Corresponds to Android's "IME_ACTION_PREVIOUS". The OS displays a
92+
/// button that represents moving backward, e.g., a left-facing arrow button.
93+
///
94+
/// iOS: iOS does not have a keyboard return type of "previous." It is
95+
/// inappropriate to choose this [TextInputAction] when running on iOS.
96+
previous,
97+
98+
/// Logical meaning: In iOS apps, it is common for a "Back" button and
99+
/// "Continue" button to appear at the top of the screen. However, when the
100+
/// keyboard is open, these buttons are often hidden off-screen. Therefore,
101+
/// the purpose of the "Continue" return key on iOS is to make the "Continue"
102+
/// button available when the user is entering text.
103+
///
104+
/// Historical context aside, [TextInputAction.continueAction] can be used any
105+
/// time that the term "Continue" seems most appropriate for the given action.
106+
///
107+
/// Android: Android does not have an IME input type of "continue." It is
108+
/// inappropriate to choose this [TextInputAction] when running on Android.
109+
///
110+
/// iOS: Corresponds to iOS's "UIReturnKeyContinue". The title displayed in the
111+
/// action button is "Continue". This action is only available on iOS 9.0+.
112+
///
113+
/// The reason that this value has "Action" post-fixed to it is because
114+
/// "continue" is a reserved word in Dart, as well as many other languages.
115+
continueAction,
116+
117+
/// Logical meaning: The user wants to join something, e.g., a wireless
118+
/// network.
119+
///
120+
/// Android: Android does not have an IME input type of "join." It is
121+
/// inappropriate to choose this [TextInputAction] when running on Android.
122+
///
123+
/// iOS: Corresponds to iOS's "UIReturnKeyJoin". The title displayed in the
124+
/// action button is "Join".
125+
join,
126+
127+
/// Logical meaning: The user wants routing options, e.g., driving directions.
128+
///
129+
/// Android: Android does not have an IME input type of "route." It is
130+
/// inappropriate to choose this [TextInputAction] when running on Android.
131+
///
132+
/// iOS: Corresponds to iOS's "UIReturnKeyRoute". The title displayed in the
133+
/// action button is "Route".
134+
route,
135+
136+
/// Logical meaning: Initiate a call to emergency services.
137+
///
138+
/// Android: Android does not have an IME input type of "emergencyCall." It is
139+
/// inappropriate to choose this [TextInputAction] when running on Android.
140+
///
141+
/// iOS: Corresponds to iOS's "UIReturnKeyEmergencyCall". The title displayed
142+
/// in the action button is "Emergency Call".
143+
emergencyCall,
144+
145+
/// Logical meaning: Insert a newline character in the focused text input,
146+
/// e.g., [TextField].
147+
///
148+
/// Android: Corresponds to Android's "IME_ACTION_NONE". The OS displays a
149+
/// button that represents a new line, e.g., a carriage return button.
150+
///
151+
/// iOS: Corresponds to iOS's "UIReturnKeyDefault". The title displayed in the
152+
/// action button is "return".
153+
///
154+
/// The term [TextInputAction.newline] exists in Flutter but not in Android
155+
/// or iOS. The reason for introducing this term is so that developers can
156+
/// achieve the common result of inserting new lines without needing to
157+
/// understand the various IME actions on Android and return keys on iOS.
158+
/// Thus, [TextInputAction.newline] is a convenience term that alleviates the
159+
/// need to understand the underlying platforms to achieve this common behavior.
160+
newline;
161+
162+
/// Displayable string representation of the enum value.
163+
String get prettify {
164+
return switch (this) {
165+
TextInputActionC.none => 'None',
166+
TextInputActionC.unspecified => 'Unspecified',
167+
TextInputActionC.done => 'Done',
168+
TextInputActionC.go => 'Go',
169+
TextInputActionC.search => 'Search',
170+
TextInputActionC.send => 'Send',
171+
TextInputActionC.next => 'Next',
172+
TextInputActionC.previous => 'Previous',
173+
TextInputActionC.continueAction => 'Continue',
174+
TextInputActionC.join => 'Join',
175+
TextInputActionC.route => 'Route',
176+
TextInputActionC.emergencyCall => 'Emergency Call',
177+
TextInputActionC.newline => 'New-line',
178+
};
179+
}
180+
}
181+
10182
/// Used to configure the auto validation of [FormField] and [Form] widgets.
11183
enum AutovalidateModeC {
12184
/// No auto validation will occur.

lib/src/api/nodes/text_field_node.dart

+8
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ class TextFieldProperties with SerializableMixin, EquatableMixin {
218218
/// device's autofill service.
219219
Set<TextInputAutofillHints> autofillHints;
220220

221+
/// The action the keyboard should take when the user presses the action
222+
/// button on the keyboard.
223+
TextInputActionC textInputAction;
224+
221225
/// Creates a [TextFieldProperties] instance with the given data.
222226
TextFieldProperties({
223227
this.autoCorrect = true,
@@ -249,6 +253,7 @@ class TextFieldProperties with SerializableMixin, EquatableMixin {
249253
this.validator = const NoneTextInputValidatorModel(),
250254
this.autovalidateMode = AutovalidateModeC.onUserInteraction,
251255
this.autofillHints = const {},
256+
this.textInputAction = TextInputActionC.none,
252257
}) : inputStyle = inputStyle ??
253258
StartEndProp.general(fontSize: 14, fills: [PaintModel.blackPaint]),
254259
decoration = decoration ?? InputDecorationModel();
@@ -285,6 +290,7 @@ class TextFieldProperties with SerializableMixin, EquatableMixin {
285290
TextInputValidatorModel? validator,
286291
Set<TextInputAutofillHints>? autofillHints,
287292
AutovalidateModeC? autovalidateMode,
293+
TextInputActionC? textInputAction,
288294
}) {
289295
return TextFieldProperties(
290296
autoCorrect: autoCorrect ?? this.autoCorrect,
@@ -317,6 +323,7 @@ class TextFieldProperties with SerializableMixin, EquatableMixin {
317323
validator: validator ?? this.validator,
318324
autofillHints: autofillHints ?? this.autofillHints,
319325
autovalidateMode: autovalidateMode ?? this.autovalidateMode,
326+
textInputAction: textInputAction ?? this.textInputAction,
320327
);
321328
}
322329

@@ -358,5 +365,6 @@ class TextFieldProperties with SerializableMixin, EquatableMixin {
358365
validator,
359366
autofillHints,
360367
autovalidateMode,
368+
textInputAction,
361369
];
362370
}

lib/src/api/nodes/text_field_node.g.dart

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)