flet-validation

Author validation rules for Flet Python control properties using Annotated V rules.

16.6k|685|Updated Mar 24, 2022
One-click install
npx skills add https://github.com/flet-dev/flet --skill flet-validation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: flet-validation
Source: https://github.com/flet-dev/flet/tree/main/.agents/skills/flet-validation
Command: npx skills add https://github.com/flet-dev/flet --skill flet-validation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Adding validation to Flet Python controls requires choosing between field-level Annotated rules, class-level validation_rules, and before_update() checks, while keeping docstrings, tests, and Dart-side behavior consistent. This Skill provides the conventions and decision order to do that correctly.

Core Features & Use Cases

  • Validation Decision Order: Guides you to prefer Annotated[..., V.*] field rules, then validation_rules for cross-field invariants, and before_update() only for normalization or non-ruleable checks.
  • Docstring Conventions: Standardizes Raises: ValueError entries per logical rule, with canonical wording sourced from the V.* helpers in flet/utils/validation.py.
  • Dart Alignment: Ensures Python-side constraints mirror Dart wrapper and Flutter widget assertions so invalid payloads fail before crossing to Dart.
  • Use Case: When adding a constrained property like a slider's min/max/value bounds, use this Skill to write the Annotated rules, matching Raises docstrings, and boundary tests.

Quick Start

Ask the AI to add validation to a Flet control property, for example to enforce that a slider's value stays between its min and max using V rules with matching docstrings and tests.

Frequently Asked Questions about flet-validation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add validation to a Flet control property in Python?▼

Add field-level rules with Annotated[..., V.*] metadata on the dataclass field, such as V.between(0.0, 1.0) for bounded numbers. Use __validation_rules__ only for cross-field invariants that field rules cannot express cleanly.

When should I use before_update() instead of V validation rules?▼

Reserve before_update() for normalization and mutation, or for invariants genuinely not expressible with existing V.* primitives. Never duplicate the same invariant in both before_update() and V rules.

How do I validate cross-field comparisons like min less than max?▼

Use field comparison rules V.gt_field, V.ge_field, V.lt_field, and V.le_field referencing the other field by name. If either side is optional and currently None, the comparison is skipped.

How should ValueError Raises docstrings be written for validated properties?▼

Add one ValueError entry per logical rule in the property docstring, starting with 'If it ...' and using canonical wording from the V.* helpers in flet/utils/validation.py. For V.between, use a single inclusive-bounds entry.

Does Python validation need to match Dart-side control behavior?▼

Yes. Review the Flet Dart wrapper and the underlying Flutter widget assertions, then mirror those constraints in Python so invalid values fail before crossing to Dart, including Dart-applied defaults.

What tests are required when adding control validation?▼

Cover one valid and one invalid case per logical rule, boundary values, cross-field set/unset combinations for optional values, and effective-default behavior. Place runtime tests in sdk/python/packages/flet/tests/test_validation.py.