import 'package:flutter/material.dart';


class NotEmptyTextFormField extends StatelessWidget {
  final String labelText;
  final String error;
  final TextEditingController controller;
  final ValueChanged<bool>? onValid;
  final String? hintText;
  final bool readOnly;

  const NotEmptyTextFormField({
    super.key,
    required this.controller,
    required this.labelText,
    required this.error,
    this.onValid,
    this.hintText,
    required this.readOnly,
  });

  bool _validate(String? value) {
    return !(value == null || value.isNotEmpty);
  }

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      controller: controller,
      decoration: InputDecoration(labelText: labelText, hintText: hintText),
      validator: (value) => _validate(value) ? error : null,
      onChanged: (value) {
        if (onValid != null) onValid!(_validate(value));
      },
      readOnly: readOnly,
    );
  }
}