import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class AddEditTextField extends StatelessWidget {
  final TextEditingController controller;
  final String hint;
  final bool onlyNumbers;
  final double padding;
  final String? Function(String?)? validator;

  const AddEditTextField({
    super.key,
    required this.controller,
    required this.hint,
    this.onlyNumbers = false,
    this.padding = 12,
    this.validator,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(padding),
      child: TextFormField(
        decoration: InputDecoration(hintText: hint),
        controller: controller,
        keyboardType: onlyNumbers ? TextInputType.number : null,
        inputFormatters:
            onlyNumbers ? [FilteringTextInputFormatter.digitsOnly] : [],
        validator: validator,
      ),
    );
  }
}
