hcValidateTextInputField function

bool hcValidateTextInputField(
  1. BuildContext context,
  2. TextEditingController controller,
  3. String fieldName, {
  4. FocusNode? focusNode,
})

Validate Text Input Field

Implementation

bool hcValidateTextInputField(
    BuildContext context, TextEditingController controller, String fieldName,
    {FocusNode? focusNode}) {
  if (controller.text.isEmpty) {
    if (focusNode != null) {
      focusNode.requestFocus();
    }
    ScaffoldMessenger.of(context).showSnackBar(SnackBar(
      content: Text('$fieldName can\'t be empty'),
    ));
    return false;
  }
  return true;
}