import 'package:flutter/cupertino.dart';

class FormFieldConstants {
  static FormFieldConstants instance() {
    return _instance;
  }

  static final FormFieldConstants _instance = FormFieldConstants._internal();

  FormFieldConstants._internal();

  factory FormFieldConstants() {
    return _instance;
  }

  final Map<String, GlobalKey<FormFieldState>> _keys = {};
  final Map<String, TextEditingController> _controllers = {};

  TextEditingController getController(String keyName) {
    return _controllers[keyName] ??= TextEditingController(); // Assign if not exist
  }

  GlobalKey<FormFieldState> getFormKey(String keyName) {
    return _keys[keyName] ??= GlobalKey<FormFieldState>(); // Assign if not exist
  }
  void clearKeysForScreen(String screenPrefix) {
    _keys.removeWhere((key, value) => key.startsWith(screenPrefix));
    _controllers.removeWhere((key, value) => key.startsWith(screenPrefix));
  }
}
