emailFormEntry method

Widget emailFormEntry({
  1. String title = 'Email',
  2. String subTitle = 'the email address',
  3. dynamic onSaved(
    1. String?
    )?,
  4. String? defaultValue,
  5. bool verified = false,
  6. bool showVerifyButton = true,
  7. VoidCallback? onVerify,
})

Implementation

Widget emailFormEntry({
  String title = 'Email',
  String subTitle = 'the email address',
  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: TextFormField(
                  style: Theme.of(context).textTheme.bodyLarge,
                  onChanged: (_) {
                    widget.formKey.currentState!.save();
                    if (widget.onModified != null) {
                      widget.onModified!();
                    }
                  },
                  enabled: isEdit,
                  controller: TextEditingController(text: defaultValue),
                  decoration: elegantInputDecoration(
                    hintText: 'Email',
                    prefix: const Icon(Icons.email),
                  ),
                  validator: (value) => value!.isEmpty
                      ? 'Email is required'
                      : (value.isValidEmail() ? null : 'Invalid email'),
                  onSaved: onSaved,
                ),
              ),
              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),
                ),
            ],
          )
        : TextFormField(
            style: Theme.of(context).textTheme.bodyLarge,
            onChanged: (_) {
              widget.formKey.currentState!.save();
              if (widget.onModified != null) {
                widget.onModified!();
              }
            },
            enabled: isEdit,
            controller: TextEditingController(text: defaultValue),
            decoration: elegantInputDecoration(
              hintText: 'Email',
              prefix: const Icon(Icons.email),
            ),
            validator: (value) => value!.isEmpty
                ? 'Email is required'
                : (value.isValidEmail() ? null : 'Invalid email'),
            onSaved: onSaved,
          ),
  );
}