Boilerplate-free form validation library

Related tags

Utilities valform
Overview

Valform

Valform

Boilerplate-free form validation library.

Preface

Why?

There is no clean and nice way to separate business logic (validation) from presentation.

Why not Formz?

Formz defies Flutter's way to handle state, forcing user to hold form state entirely in business logic.

But it can't be done in Flutter. State is inevitably stored in TextEditingControllers. Formatters are applied inside widget itself.

When I use formz, I always find myself copy-pasting form inputs and struggling with simple use cases.

Why Valform?

  • Minimalistic.
  • Perfectly fits flutter's form handling system.
  • Your teammates just need to explore a couple of simple concepts.

Simple Usage

Use case: We want to validate that email doesn't exist in our database. If it does, display error.

submit() { await Future.delayed(Duration(seconds: 1)); // access the database _emailAlreadyExists = Vf(); notifyListeners(); } } ">
class LoginFormState extends ChangeNotifier {
  Vf _emailAlreadyExists;

  LoginFormState([
    this._emailAlreadyExists = const VfReproduce.sealed()
  ]);

  String? validateEmail(String? email) {
    if (_emailAlreadyExists.access(email)) {
      return "Email already exists";
    }

    return null;
  }

  Future<void> submit() {
    await Future.delayed(Duration(seconds: 1)); // access the database
    _emailAlreadyExists = Vf();
    notifyListeners();
  }
}

Somewhere in Flutter code:

final loginFormState = LoginFormState();

void initState() {
  super.initState();
  loginFormState.addListener(() => setState(() {}));
}

Widget build(BuildContext context) => Column(
  children: [
    TextFormField(
      validator: loginFormState.validateEmail,
    ),
    OutlinedButton(onPressed: loginFormState.submit),
  ]
);

Inspiration

The whole work was inspired by event concept in async_redux, created by Marcelo Glasberg.

You might also like...

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

Oct 8, 2021

A comprehensive, cross-platform path manipulation library for Dart.

A comprehensive, cross-platform path manipulation library for Dart. The path package provides common operations for manipulating paths: joining, split

Dec 29, 2022

A fast algorithm for finding polygon pole of inaccessibility implemented as a Dart library.

polylabel Dart port of https://github.com/mapbox/polylabel. A fast algorithm for finding polygon pole of inaccessibility implemented as a Dart library

Nov 13, 2021

Dart library for unescaping HTML-encoded strings

html_unescape A Dart library for unescaping HTML-encoded strings. Supports: Named Character References ( ) 2099 of them Decimal Character Referen

Dec 20, 2022

The `TypedEventNotifier` library allows notifying listeners with an object.

The TypedEventNotifier library allows notifying listeners with an object. listeners can be subscribed to only a special type or group of objects.

Nov 13, 2021

A utility library to automate mobile emulators.

emulators A utility library to automate mobile emulators. Can be used to automate screenshots on multiple devices. Example project https://github.com/

Nov 13, 2022

This is a dart library covering nearly 100% of the latest Planning Center public API.

Planning Center API for Dart Planning Center is an online platform for church management. It provides multiple apps for things like check-ins, service

Oct 6, 2022

A JMAP client library in Dart to make JMAP method calls and process the responses

JMAP Dart client A JMAP client library to make JMAP method calls and process the responses. We most notably use it to write the TMail Flutter applicat

Dec 19, 2022

Library for help you make userbot or bot telegram and support tdlib telegram database and only support nodejs dart and google-apps-script

To-Do telegram client dart ✅️ support multi token ( bot / userbot ) ✅️ support bot and userbot ✅️ support telegram-bot-api local server ✅️ support tel

Jan 7, 2023
Owner
Alexander Farkas
Alexander Farkas
Redux Compact is a library that aims to reduce the massive amount of boilerplate that follows maintaining a Flutter Redux application.

Redux Compact Redux Compact is a library that aims to reduce the massive amount of boilerplate that follows maintaining a Flutter Redux application. T

Ómar Óskarsson 9 Apr 8, 2022
An application built using Flutter that holds a static personal/professional informations related to me in the form of card.(Digital Visiting Card)

mi_card_flutter A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you star

dev_allauddin 3 Feb 3, 2022
MB Contact Form is a basic flutter widget which helps you for your contact page.

mb_contact_form is a third party flutter package. This is a simple version of Contact Form. This can be easily added to your flutter projects. This make your works simpler and your code shorter. This is recently updated and has null safety too.

Mouli Bheemaneti 2 Oct 17, 2022
Let's Encrypt support for the shelf package (free and automatic HTTPS certificate support).

shelf_letsencrypt shelf_letsencrypt brings support for Let's Encrypt to the shelf package. Usage To use the LetsEncrypt class import 'dart:io'; impor

Graciliano Monteiro Passos 8 Oct 31, 2022
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

Luke Pighetti 3.5k Jan 4, 2023
A Dart library to parse Portable Executable (PE) format

pefile A Dart library to parse Portable Executable (PE) format Usage A simple usage example: var pe = pefile.parse('C:\\Windows\\System32\\notepad.exe

null 4 Sep 12, 2022
This library contains methods that make it easy to consume Mpesa Api.

This library contains methods that make it easy to consume Mpesa Api. It's multi-platform, and supports CLI, server, mobile, desktop, and the browser.

Eddie Genius 3 Dec 15, 2021
Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more!

Scribble Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more! A

Tim Created It. 73 Dec 16, 2022
An alternative random library for Dart.

Randt Randt library for Dart... Description Use Randt to get a random integer from a list, generate random integer in a specific range and generate ra

Bangladesh Coding Soldierz 3 Nov 21, 2021
A library for YAML manipulation with comment and whitespace preservation.

Yaml Editor A library for YAML manipulation while preserving comments. Usage A simple usage example: import 'package:yaml_edit/yaml_edit.dart'; void

Dart 17 Dec 26, 2022