ReactivePhoneContactPicker<T> constructor

ReactivePhoneContactPicker<T>({
  1. Key? key,
  2. String? formControlName,
  3. FormControl<T>? formControl,
  4. Map<String, ValidationMessageFunction>? validationMessages,
  5. ControlValueAccessor<T, PhoneContact>? valueAccessor,
  6. ShowErrorsFunction<T>? showErrors,
  7. InputDecoration decoration = decorationInvisible,
  8. required ContactBuilder<PhoneContact> contactBuilder,
  9. GestureBuilder? gestureBuilder,
  10. double disabledOpacity = 0.5,
})

Creates a ReactivePhoneContactPicker that contains a ContactPicker.

Can optionally provide a formControl to bind this widget to a control.

Can optionally provide a formControlName to bind this ReactiveFormField to a FormControl.

Must provide one of the arguments formControl or a formControlName, but not both at the same time.

Can optionally provide a validationMessages argument to customize a message for different kinds of validation errors.

Can optionally provide a valueAccessor to set a custom value accessors. See ControlValueAccessor.

Can optionally provide a showErrors function to customize when to show validation messages. Reactive Widgets make validation messages visible when the control is INVALID and TOUCHED, this behavior can be customized in the showErrors function.

Example:

Binds a text field.

final form = fb.group({'email': Validators.required});

ReactivePhoneContactPicker(
  formControlName: 'email',
),

Binds a text field directly with a FormControl.

final form = fb.group({'email': Validators.required});

ReactivePhoneContactPicker(
  formControl: form.control('email'),
),

Customize validation messages

ReactivePhoneContactPicker(
  formControlName: 'email',
  validationMessages: {
    ValidationMessage.required: 'The email must not be empty',
    ValidationMessage.email: 'The email must be a valid email',
  }
),

Customize when to show up validation messages.

ReactivePhoneContactPicker(
  formControlName: 'email',
  showErrors: (control) => control.invalid && control.touched && control.dirty,
),

For documentation about the various parameters, see the ContactPicker class and ContactPicker, the constructor.

Implementation

ReactivePhoneContactPicker({
  super.key,
  super.formControlName,
  super.formControl,
  super.validationMessages,
  super.valueAccessor,
  super.showErrors,

  ////////////////////////////////////////////////////////////////////////////
  InputDecoration decoration = decorationInvisible,
  required ContactBuilder<PhoneContact> contactBuilder,
  GestureBuilder? gestureBuilder,
  double disabledOpacity = 0.5,
}) : super(
        builder: (field) {
          final InputDecoration effectiveDecoration = decoration
              .applyDefaults(Theme.of(field.context).inputDecorationTheme);

          void pickContact() async {
            field.didChange(await FlutterContactPicker.pickPhoneContact());
          }

          final child = InkWell(
            onTap: pickContact,
            child: InputDecorator(
              decoration: effectiveDecoration.copyWith(
                errorText: field.errorText,
                enabled: field.control.enabled,
              ),
              child: contactBuilder.call(field.value),
            ),
          );

          return IgnorePointer(
            ignoring: !field.control.enabled,
            child: Listener(
              onPointerDown: (_) => field.control.markAsTouched(),
              child: Opacity(
                opacity: field.control.enabled ? 1 : disabledOpacity,
                child: gestureBuilder?.call(pickContact, child) ?? child,
              ),
            ),
          );
        },
      );