nit_generic_forms 0.0.3

SDKflutter
Platformandroidioswindowslinuxmacosweb

Generic forms for editing any models through configuration enums

Set of tools to create generic forms for creating and editing entities based on configuration enums

Features

NiT Generic Forms allow: -create simple forms with validation -save new models and update existing -create generic layouts like admin panels

Getting started

For example if you want to show a dialog with editing form you can simply:

await context.showForceDialog(
  NitGenericForm<Task, TaskFormDescriptor>(
    model: model,
    entityManager: NitGenericEntityManager<Task>(
      saveAction: ref.read(taskListStateProvider.notifier).saveTask,
    ),
    fields: TaskFormDescriptor.values,
  ),
);

You only need to provide:

  1. current model (or null if it's a create form)
  2. entityManager - object implementing interface for saving the updated model (and delete action if needed)
  3. fields - list of enum values implementing NitGenericFormsFieldsEnum

Usage

Example of the enum:

enum TaskFormDescriptor<T> implements NitGenericFormsFieldsEnum<Task> {
  id(
    NitHiddenFieldDescriptor<int>(),
  ),
  title(
    NitTextFieldDescriptor<String>(displayTitle: 'Заголовок'),
  ),
  description(
    NitTextFieldDescriptor<String>(displayTitle: 'Описание'),
  );

  const TaskFormDescriptor(
    this.fieldDescriptor,
  );

  @override
  final NitFormFieldDescriptor<T> fieldDescriptor;

  @override
  initialValue(Task? model) => switch (this) {
        id => model?.id,
        title => model?.title,
        description => model?.description,
      } as T?;

  @override
  Task save(Task? model, Map<NitGenericFormsFieldsEnum, dynamic> values) {
    return Task(
      id: values[id] ?? model?.id,
      title: values[title] ?? model?.title,
      description: values[description] ?? model?.description,
    );
  }
}

Additional information

If you need additional field types and configuration options, please, feel free to contact me on telegram https://t.me/eu_novikov