editable_model_form 0.0.3 copy "editable_model_form: ^0.0.3" to clipboard
editable_model_form: ^0.0.3 copied to clipboard

Make your model editable with ease

Make a simple form that can switch between editable and not editable mode from a simple class model.

Features #

Show a form that can be editable or not editable from a simple class model. Act on result of the submitting the form. No need to write a lot of code to make a simple form.

Usage #

Create a model class that extends from EditableModel.

class ForgetPasswordFormModel extends EditableModel<ForgetPasswordFormModel> {
  final String email;

  ForgetPasswordFormModel({required this.email});

  ForgetPasswordFormModel.fromJson(Map<String, Object?>? json)
      : this(
          email: json.getValueOr(
            name: 'email',
            defaultValue: "",
          ),
        );

  @override
  ForgetPasswordFormModel fromEditJson(Map<String, dynamic> json) =>
      ForgetPasswordFormModel.fromJson(json);

  @override
  List<FormViewType> getFormViewTypes() {
    return [
      FormEmailInputViewType(
        key: "email",
        label: "email:",
        icon: const Icon(Icons.email),
        defaultValue: email,
      ),
    ];
  }

  Map<String, Object?> toJson() {
    return {
      'email': email,
    };
  }
}

Create the form widget.

EditFormScreen<ForgetPasswordFormModel>(
          title: "Enter your email address",
          editableModel: ForgetPasswordFormModel(email: ""),
          onSubmit: (result) {
            debugPrint("onSubmit called. result:${result.toJson()}");
            
            // Do the process of submitting the form here.

            Navigator.pop(context);
          },
        ).showInDialog(context: context, title: "Reset Password")