textFormField method

Widget textFormField({
  1. required TextEditingController controller,
  2. required String labelText,
  3. void onChanged(
    1. String
    )?,
  4. String? validator(
    1. String?
    )?,
  5. TextInputType? keyboardType,
  6. double? maxWidth,
  7. int? maxLines,
  8. bool? obscureText,
  9. void onPressedSuffixIcon()?,
  10. IconData? suffixIcon,
})

customized text form field with default option

Implementation

Widget textFormField({
  required TextEditingController controller,
  required String labelText,
  void Function(String)? onChanged,
  String? Function(String?)? validator,
  TextInputType? keyboardType,
  double? maxWidth,
  int? maxLines,
  bool? obscureText,
  void Function()? onPressedSuffixIcon,
  IconData? suffixIcon,
}) {
  return Container(
    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(10),
      boxShadow: [
        BoxShadow(
          color: Colors.black.withOpacity(0.3),
          blurRadius: 8,
          offset: const Offset(0, 3),
        ),
      ],
    ),
    constraints: BoxConstraints(
      maxWidth: maxWidth ?? 370,
    ),
    child: TextFormField(
      maxLines: maxLines ?? 1,
      controller: controller,
      obscureText: obscureText ?? false,
      onChanged: onChanged,
      decoration: InputDecoration(
        labelText: labelText,
        labelStyle: const TextStyle(color: Colors.grey),
        alignLabelWithHint: true,
        suffixIcon: onPressedSuffixIcon != null
            ? IconButton(
                onPressed: onPressedSuffixIcon,
                icon: obscureText != null
                    ? Icon(
                        obscureText
                            ? Icons.remove_red_eye
                            : CupertinoIcons.eye_slash_fill,
                        color: themeColor,
                      )
                    : Icon(
                        suffixIcon ?? Icons.remove_red_eye,
                        color: themeColor,
                      ),
              )
            : suffixIcon != null
                ? Icon(
                    suffixIcon,
                    color: themeColor,
                  )
                : null,
        hintStyle: const TextStyle(
          color: Colors.grey,
        ),
        errorStyle: const TextStyle(
          fontSize: 0,
        ),
        hintText: labelText,
        contentPadding:
            const EdgeInsets.symmetric(horizontal: 14, vertical: 16),
        filled: true,
        fillColor: primaryColor,
        floatingLabelBehavior: FloatingLabelBehavior.never,
        focusedBorder: OutlineInputBorder(
          borderSide: const BorderSide(color: Colors.grey, width: 1.0),
          borderRadius: BorderRadius.circular(10),
          gapPadding: 0,
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10),
          borderSide:
              BorderSide(color: Colors.grey.withOpacity(0.5), width: 1.0),
          gapPadding: 0,
        ),
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10.0),
          borderSide: const BorderSide(color: Colors.transparent, width: 1.0),
        ),
      ),
      validator: validator,
      keyboardType: keyboardType,
      style: const TextStyle(
        fontFamily: "Poppins",
      ),
    ),
  );
}