valiform 0.0.1 copy "valiform: ^0.0.1" to clipboard
valiform: ^0.0.1 copied to clipboard

Valiform is a Flutter form validation library based on Validart. It provides efficient and reactive validations for various field types.

pub package package publisher

Valiform #

Valiform is a package for managing and validating forms in Flutter, built on top of validart. It provides a simple interface for handling form states, validation, and integration with FormState.

Installation #

Add valiform to your project:

flutter pub add valiform

This will add a line like this to your project's pubspec.yaml:

dependencies:
  valiform: <version>

Basic Usage #

import 'package:flutter/material.dart';
import 'package:valiform/valiform.dart';

final v = Validart();

void main() {
  final form = v.map({
    'name': VString(minLength: 3),
    'age': VInt(min: 18),
  }).form();
}

Using the Form's Listenable for Reactivity #

You can use the listenable property of the form or individual fields to reactively update the UI:

class ExampleWidget extends StatelessWidget {
  final VForm form;

  const ExampleWidget({super.key, required this.form});

  @override
  Widget build(BuildContext context) {
    return ObserverWidget(
      listenable: form.listenable,
      builder: (context) {
        return Text("Current Form Value: ${form.value}");
      },
    );
  }
}

class ObserverWidget extends StatelessWidget {
  final Listenable listenable;
  final WidgetBuilder builder;

  const ObserverWidget({
    super.key,
    required this.listenable,
    required this.builder,
  });

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: listenable,
      builder: (context, __) => builder(context),
    );
  }
}

Using Default Values #

You can provide default values to the form and access them in initialValue for TextFormField or by using a controller:

final form = v.map({
  'email': v.string().email()
}).form(defaultValues: {'email': 'example@email.com'});

Using initialValue in a TextFormField:

TextFormField(
  initialValue: form.field('email').value,
)

Or using the field's controller:

TextFormField(
  controller: form.field('email').controller,
)
1
likes
0
points
2
downloads

Publisher

verified publisheredunatalec.com

Weekly Downloads

Valiform is a Flutter form validation library based on Validart. It provides efficient and reactive validations for various field types.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, validart

More

Packages that depend on valiform