Getting Started with Forms (Beta)

This section provides a step-by-step guide on how to set up and use the Forms package in your Flutter project.

Step 1: Add the dependency

To use the Forms package, you need to add it as a dependency in your pubspec.yaml file:

dependencies:
  forms: ^latest_version

Replace latest_version with the version of Forms you want to use.

Step 2: Install the package

After adding the dependency, you can install it by running the following command in your terminal:

flutter pub get

Step 3: Import the package

Now, you can import the Forms package in your Dart file:

import 'package:forms/forms.dart';

Step 4: Use the package

You can now use the Forms package to create forms in your Flutter application. Here's a basic example:

Forms(
formElements: <FormControls>[...], // List of form controls
onChanged: (value) {...}, // Function to handle form changes
padding: 10.0, // Padding around the form
formMap: {...}, // Map of form values
errorMessages: {...}, // Map of error messages
validations: {...}, // Map of validation rules
decorations: {...}, // Map of decoration settings
hideSaveBtn: false, // Whether to hide the save button
buttonSave: CustomSaveButton(), // Custom save button widget
actionSave: (formKey) {...}, // Function to handle form submission
);

That's it! You're now ready to start building forms with the Forms package. For more detailed usage and customization options, please refer to the other sections of this documentation.

Forms Usage Documentation

Forms is a Flutter package that provides a simple and flexible way to build forms in your Flutter applications. It supports a variety of form controls and allows for easy customization and validation.

API Reference

This section provides a brief overview of the main classes and methods in the Forms package. For a more detailed API reference, please refer to the source code.

Forms

The main class in the package. It is used to create a form.

Properties

  • formElements: A list of FormControls that make up the form.
  • onChanged: A function that is called when the form changes.
  • padding: The padding around the form.
  • formMap: A map of form values.
  • errorMessages: A map of error messages.
  • validations: A map of validation rules.
  • decorations: A map of decoration settings.
  • hideSaveBtn: A boolean indicating whether to hide the save button.
  • buttonSave: A custom save button widget.
  • actionSave: A function to handle form submission.

FormControls

A class that represents a form control.

Properties

  • controlType: The type of the form control (e.g., text input, dropdown, toggle switch, etc.).
  • controlConfig: The configuration for the control (e.g., label, value, visibility, etc.).

FormControlTypes

An enumeration of the different types of form controls.

FormControlConfig

A class that defines the configuration for a form control.

Properties

  • isVisible: A boolean indicating whether the control is visible.
  • label: The label for the control.
  • value: The initial value of the control.

Please note that this is a simplified API reference. The actual API may contain additional classes, methods, and properties.

Basic Usage

To create a form, you need to instantiate the Forms class and pass in the necessary parameters. Here's an example:

Forms(
  formElements: <FormControls>[...], // List of form controls
  onChanged: (value) {...}, // Function to handle form changes
  padding: 10.0, // Padding around the form
  formMap: {...}, // Map of form values
  errorMessages: {...}, // Map of error messages
  validations: {...}, // Map of validation rules
  decorations: {...}, // Map of decoration settings
  hideSaveBtn: false, // Whether to hide the save button
  actionSave: (formKey) {...}, // Function to handle form submission
  actionButtonTextStyle: ButtonStyle(...), // Custom save button style
);

Form Controls

Forms supports a variety of form controls, which are defined in the formElements parameter. Each form control is an instance of the FormControls class, which takes a controlType and a controlConfig.

Here's an example of a text input control:

FormControls(
  controlType: FormControlTypes.textInput,
  controlConfig: FormControlConfig(
    isVisible: true,
    label: 'Username',
    value: 'default',
    // other configurations...
  ),
)

The controlType determines the type of the form control (e.g., text input, dropdown, toggle switch, etc.), and the controlConfig defines the configuration for the control (e.g., label, value, visibility, etc.).

Validation

Forms supports form validation through the validations parameter. This is a map where the keys are the form control names and the values are the validation rules.

Here's an example of a validation rule:

validations: {
  'username': (value) {
    if (value.isEmpty) {
      return 'Please enter your username.';
    }
    return null;
  },
}

Saving the Form

When the user presses the save button, the actionSave function is called. This function receives the form key, which can be used to validate and save the form.

Here's an example of a save function:

actionSave: (formKey) {
  if (formKey.currentState!.validate()) {
    formKey.currentState!.save();
    // handle form submission...
  }
}

That's the basic usage of Forms. For more advanced usage and customization options, please refer to the source code and comments in the forms package.

Additional Information

More Information For more detailed information about the Forms package, please refer to the source code and comments in the forms package. You can also find more usage examples and advanced customization options there.

Contributing

We welcome contributions from the community. If you'd like to contribute, please fork the repository and submit a pull request. Before submitting your pull request, make sure to test your changes thoroughly.

Filing Issues

If you encounter any problems or have suggestions for improvements, please file an issue on the GitHub repository. When filing an issue, please provide as much detail as possible about the problem, including the steps to reproduce it and any error messages.

Response from the Authors

We aim to respond to all issues and pull requests as quickly as possible. However, please keep in mind that this is an open-source project and we're doing this in our spare time. We appreciate your patience.

More

We're always looking for ways to improve Forms. If you have any ideas or suggestions, don't hesitate to share them with us. We're also open to collaborations, so if you're interested in working with us on this project, please get in touch.

Thank you for using Forms!