{"id":13551308,"url":"https://github.com/VeryGoodOpenSource/formz","last_synced_at":"2025-04-03T01:32:05.350Z","repository":{"id":40473845,"uuid":"262193392","full_name":"VeryGoodOpenSource/formz","owner":"VeryGoodOpenSource","description":"A unified form representation in Dart used at Very Good Ventures 🦄","archived":false,"fork":false,"pushed_at":"2024-12-20T19:58:08.000Z","size":281,"stargazers_count":434,"open_issues_count":9,"forks_count":39,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-30T22:05:55.236Z","etag":null,"topics":["dart","dart-package","dartlang","form-validation","form-validator","forms"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/formz","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VeryGoodOpenSource.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-08T01:04:01.000Z","updated_at":"2025-03-28T19:34:16.000Z","dependencies_parsed_at":"2023-02-06T09:32:31.542Z","dependency_job_id":"a1f1c0ad-a1c0-4ac0-a5be-d83b90932f3f","html_url":"https://github.com/VeryGoodOpenSource/formz","commit_stats":{"total_commits":65,"total_committers":11,"mean_commits":5.909090909090909,"dds":0.6923076923076923,"last_synced_commit":"54eaea0b099d59d630036af4abfbce670966dc72"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VeryGoodOpenSource%2Fformz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VeryGoodOpenSource%2Fformz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VeryGoodOpenSource%2Fformz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VeryGoodOpenSource%2Fformz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VeryGoodOpenSource","download_url":"https://codeload.github.com/VeryGoodOpenSource/formz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246922240,"owners_count":20855341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","dart-package","dartlang","form-validation","form-validator","forms"],"created_at":"2024-08-01T12:01:45.935Z","updated_at":"2025-04-03T01:32:04.706Z","avatar_url":"https://github.com/VeryGoodOpenSource.png","language":"Dart","funding_links":[],"categories":["Dart"],"sub_categories":[],"readme":"# 📝 Formz\n\n[![Very Good Ventures][logo_black]][very_good_ventures_link_light]\n[![Very Good Ventures][logo_white]][very_good_ventures_link_dark]\n\nDeveloped with 💙 by [Very Good Ventures][very_good_ventures_link] 🦄\n\n[![ci][ci_badge]][ci_link]\n[![coverage][coverage_badge]][ci_link]\n[![pub package][pub_badge]][pub_link]\n[![License: MIT][license_badge]][license_link]\n[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_badge_link]\n\n---\n\nA unified form representation in Dart.\nFormz aims to simplify form representation and validation in a generic way.\n\n## Create a FormzInput\n\n```dart\nimport 'package:formz/formz.dart';\n\n// Define input validation errors\nenum NameInputError { empty }\n\n// Extend FormzInput and provide the input type and error type.\nclass NameInput extends FormzInput\u003cString, NameInputError\u003e {\n  // Call super.pure to represent an unmodified form input.\n  const NameInput.pure() : super.pure('');\n\n  // Call super.dirty to represent a modified form input.\n  const NameInput.dirty({String value = ''}) : super.dirty(value);\n\n  // Override validator to handle validating a given input value.\n  @override\n  NameInputError? validator(String value) {\n    return value.isEmpty ? NameInputError.empty : null;\n  }\n}\n```\n\n## Interact with a FormzInput\n\n```dart\nconst name = NameInput.pure();\nprint(name.value); // ''\nprint(name.isValid); // false\nprint(name.error); // NameInputError.empty\nprint(name.displayError); // null\n\nconst joe = NameInput.dirty(value: 'joe');\nprint(joe.value); // 'joe'\nprint(joe.isValid); // true\nprint(joe.error); // null\nprint(name.displayError); // null\n```\n\n## Validate Multiple FormzInput Items\n\n```dart\nconst validInputs = \u003cFormzInput\u003e[\n  NameInput.dirty(value: 'jan'),\n  NameInput.dirty(value: 'jen'),\n  NameInput.dirty(value: 'joe'),\n];\n\nprint(Formz.validate(validInputs)); // true\n\nconst invalidInputs = \u003cFormzInput\u003e[\n  NameInput.dirty(),\n  NameInput.dirty(),\n  NameInput.dirty(),\n];\n\nprint(Formz.validate(invalidInputs)); // false\n```\n\n## Automatic Validation\n\n```dart\nclass LoginForm with FormzMixin {\n  LoginForm({\n    this.username = const Username.pure(),\n    this.password = const Password.pure(),\n  });\n\n  final Username username;\n  final Password password;\n\n  @override\n  List\u003cFormzInput\u003e get inputs =\u003e [username, password];\n}\n\nvoid main() {\n  print(LoginForm().isValid); // false\n}\n```\n\n## Caching validation results\n\nFor cases where the validator method has an expensive implementation, consider using the `FormzInputErrorCacheMixin` mixin to cache the `error` result and improve performance.\n\n```dart\nimport 'package:formz/formz.dart';\n\nenum EmailValidationError { invalid }\n\nclass Email extends FormzInput\u003cString, EmailValidationError\u003e\n    with FormzInputErrorCacheMixin {\n  Email.pure([super.value = '']) : super.pure();\n\n  Email.dirty([super.value = '']) : super.dirty();\n\n  static final _emailRegExp = RegExp(\n    r'^[a-zA-Z\\d.!#$%\u0026’*+/=?^_`{|}~-]+@[a-zA-Z\\d-]+(?:\\.[a-zA-Z\\d-]+)*$',\n  );\n\n  @override\n  EmailValidationError? validator(String value) {\n    return _emailRegExp.hasMatch(value) ? null : EmailValidationError.invalid;\n  }\n}\n```\n\n[ci_badge]: https://github.com/VeryGoodOpenSource/formz/actions/workflows/main.yaml/badge.svg\n[ci_link]: https://github.com/VeryGoodOpenSource/formz/actions\n[coverage_badge]: https://raw.githubusercontent.com/VeryGoodOpenSource/formz/main/coverage_badge.svg\n[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[license_link]: https://opensource.org/licenses/MIT\n[logo_black]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_black.png#gh-light-mode-only\n[logo_white]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_white.png#gh-dark-mode-only\n[pub_badge]: https://img.shields.io/pub/v/formz.svg\n[pub_link]: https://pub.dartlang.org/packages/formz\n[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg\n[very_good_analysis_badge_link]: https://pub.dev/packages/very_good_analysis\n[very_good_ventures_link]: https://verygood.ventures\n[very_good_ventures_link_dark]: https://verygood.ventures#gh-dark-mode-only\n[very_good_ventures_link_light]: https://verygood.ventures#gh-light-mode-only","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVeryGoodOpenSource%2Fformz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVeryGoodOpenSource%2Fformz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVeryGoodOpenSource%2Fformz/lists"}