add method

void add({
  1. required String text,
  2. required FlValidator validator,
  3. required String name,
  4. bool isLock = false,
})

Implementation

void add({
  required String text,
  required FlValidator validator,
  required String name,
  bool isLock = false,
}) {
  final currentForm = value[name];

  final form = MapEntry(
    name,
    switch (currentForm) {
      null => FlFormzInput.pure(
          name: name,
          validation: validator,
          value: text,
        ),
      _ => FlFormzInput.dirty(
          name: name,
          validation: validator,
          value: text,
        )
    },
  );

  if ((currentForm?.isPure ?? true) && !form.value.isPure && text.isEmpty) {
    return;
  }

  Future(() {
    value = {...value, form.key: form.value};
  });
}