Skip to content

Commit f17198a

Browse files
committed
feat(authenticator): allow SignUp form fields to be disabled or hidden
- Add enabledOverride and visible to AuthenticatorFormField and include in diagnostics - Use enabledOverride to determine enabled state; honor override in ConfirmSignUpFormField - Render hidden fields offstage with Visibility maintaining state (so programmatic updates still sync) - Propagate enabled/visible through SignUpFormField factory APIs and concrete field constructors - Add tests verifying disabled fields still sync with controllers and hidden fields retain state synchronization
1 parent 7e71fa7 commit f17198a

File tree

5 files changed

+277
-5
lines changed

5 files changed

+277
-5
lines changed

packages/authenticator/amplify_authenticator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Enables pre-populating fields (e.g., from GPS/API data) and auto-filling verification codes
99
- Bidirectional sync between controller and internal state
1010
- Compatible with standard `TextEditingController` for flexibility
11+
- feat(authenticator): Allow SignUpFormField inputs to be disabled or hidden so apps can prefill values programmatically or keep legacy attributes off-screen
1112

1213
## 2.3.8
1314

packages/authenticator/amplify_authenticator/lib/src/widgets/form_field.dart

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ abstract class AuthenticatorFormField<
6666
FormFieldValidator<FieldValue>? validator,
6767
this.requiredOverride,
6868
this.autofillHints,
69+
this.enabledOverride,
70+
this.visible = true,
6971
}) : validatorOverride = validator;
7072

7173
/// Resolver key for the title
@@ -99,6 +101,17 @@ abstract class AuthenticatorFormField<
99101
/// Optional text controller exposed by text-driven form fields.
100102
TextEditingController? get controller => null;
101103

104+
/// Whether the field can receive manual input.
105+
///
106+
/// When `null`, the widget decides its enabled state.
107+
final bool? enabledOverride;
108+
109+
/// Whether the field should be rendered.
110+
///
111+
/// When `false`, the field stays offstage so programmatic updates can still
112+
/// run without occupying layout space.
113+
final bool visible;
114+
102115
/// Whether the field is required in the form.
103116
///
104117
/// Defaults to `false`.
@@ -131,7 +144,9 @@ abstract class AuthenticatorFormField<
131144
..add(IterableProperty<String>('autofillHints', autofillHints))
132145
..add(
133146
DiagnosticsProperty<TextEditingController?>('controller', controller),
134-
);
147+
)
148+
..add(DiagnosticsProperty<bool?>('enabledOverride', enabledOverride))
149+
..add(DiagnosticsProperty<bool>('visible', visible));
135150
}
136151
}
137152

@@ -172,7 +187,7 @@ abstract class AuthenticatorFormFieldState<
172187
FieldValue? get initialValue => null;
173188

174189
/// Whether the form field accepts input.
175-
bool get enabled => true;
190+
bool get enabled => widget.enabledOverride ?? true;
176191

177192
/// Widget to show at leading end, typically an [Icon].
178193
Widget? get prefix => null;
@@ -270,7 +285,7 @@ abstract class AuthenticatorFormFieldState<
270285
@nonVirtual
271286
@override
272287
Widget build(BuildContext context) {
273-
return Container(
288+
final field = Container(
274289
margin: EdgeInsets.only(bottom: marginBottom ?? 0),
275290
child: Stack(
276291
children: [
@@ -286,6 +301,17 @@ abstract class AuthenticatorFormFieldState<
286301
],
287302
),
288303
);
304+
if (widget.visible) {
305+
return field;
306+
}
307+
return Visibility(
308+
visible: false,
309+
maintainState: true,
310+
maintainAnimation: true,
311+
maintainSemantics: false,
312+
maintainInteractivity: false,
313+
child: field,
314+
);
289315
}
290316

291317
@override

packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/confirm_sign_up_form_field.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ abstract class _ConfirmSignUpFormFieldState<FieldValue extends Object>
9494

9595
@override
9696
bool get enabled {
97+
final override = widget.enabledOverride;
98+
if (override != null) {
99+
return override;
100+
}
97101
switch (widget.field) {
98102
case ConfirmSignUpField.code:
99103
return true;

0 commit comments

Comments
 (0)