phoneFormEntry method

Widget phoneFormEntry({
  1. String title = 'Phone',
  2. String subTitle = 'the phone number',
  3. dynamic onSaved(
    1. String?
    )?,
  4. String? defaultValue,
  5. bool verified = false,
  6. bool showVerifyButton = true,
  7. VoidCallback? onVerify,
})

Implementation

Widget phoneFormEntry({
  String title = 'Phone',
  String subTitle = 'the phone number',
  Function(String?)? onSaved,
  String? defaultValue,
  bool verified = false,
  bool showVerifyButton = true,
  VoidCallback? onVerify,
}) {
  return formEntry(
    title: title,
    subTitle: subTitle,
    inputWidget: showVerifyButton
        ? Row(
            children: [
              Expanded(
                child: PhoneField(
                  isRequired: true,
                  isEditable: isEdit,
                  defaultNumber:
                      defaultValue != null &&
                          defaultValue.isNotEmpty &&
                          defaultValue.length > 10
                      ? defaultValue.substring(
                          defaultValue.length - 10,
                          defaultValue.length,
                        )
                      : null,
                  defaultCountryCode:
                      defaultValue != null &&
                          defaultValue.isNotEmpty &&
                          defaultValue.length > 10
                      ? defaultValue.substring(0, defaultValue.length - 10)
                      : null,
                  onChanged: (value) {
                    widget.formKey.currentState!.save();
                    if (widget.onModified != null) {
                      widget.onModified!();
                    }
                  },
                  onSaved: onSaved,
                ),
              ),
              if (defaultValue != null && defaultValue.isNotEmpty)
                if (verified)
                  const Padding(
                    padding: EdgeInsets.only(left: 8.0),
                    child: Icon(Icons.check_circle, color: Colors.green),
                  )
                else if (showVerifyButton)
                  Padding(
                    padding: EdgeInsets.only(left: smallPadding),
                    child: SecondaryFlatButton(
                      onPressed: onVerify,
                      child: const Text('Verify'),
                    ),
                  )
                else
                  const Padding(
                    padding: EdgeInsets.only(left: 8.0),
                    child: Icon(
                      Icons.check_circle,
                      color: Colors.transparent,
                    ),
                  ),
            ],
          )
        : PhoneField(
            isRequired: true,
            isEditable: isEdit,
            defaultNumber:
                defaultValue != null &&
                    defaultValue.isNotEmpty &&
                    defaultValue.length > 10
                ? defaultValue.substring(
                    defaultValue.length - 10,
                    defaultValue.length,
                  )
                : null,
            defaultCountryCode:
                defaultValue != null &&
                    defaultValue.isNotEmpty &&
                    defaultValue.length > 10
                ? defaultValue.substring(0, defaultValue.length - 10)
                : null,
            onChanged: (value) {
              widget.formKey.currentState!.save();
              if (widget.onModified != null) {
                widget.onModified!();
              }
            },
            onSaved: onSaved,
          ),
  );
}