flod 1.1.2
flod: ^1.1.2 copied to clipboard
Strict, fast, type-safe data validation and transformation for Dart and Flutter.
1.1.2 #
Pub #
- Add package
topics(validation,forms,json,dio,schema) for better discoverability on pub.dev.
1.1.1 #
Docs #
- Remove
example/high_ex.dartfrom the README run instructions — that file is excluded from the published package via.pubignore, so the command is not available to pub.dev consumers.
1.1.0 #
Form & schema expressiveness release. Adds Zod-parity pieces that unblock Flutter forms and recursive data, plus a silent default-sharing fix.
Added — Flod.coerce.* (Zod z.coerce) #
-
Flod.coerce.int()/.double()/.boolean()/.string()coerce before type checks and rules. -
Typical Flutter form / stringly JSON usage:
Flod.object({ 'age': Flod.coerce.int().min(18), 'price': Flod.coerce.double().nonNegative(), 'active': Flod.coerce.boolean(), }).safeParse({'age': '22', 'price': '9.99', 'active': 'yes'}); -
Accepted inputs (exact):
- int:
int, othernum, numericString,bool(true→1 /false→0) - double:
double,int/num, numericString,bool - boolean:
bool,0/1, stringstrue/false/1/0/yes/no/on/off(case-insensitive) - string: any non-null via
Object.toString()
- int:
-
Plain
Flod.int()/Flod.boolean()remain strict (no coercion) — usecoercewhen input may be aString.
Added — Flod.lazy(() => schema) (Zod .lazy()) #
-
Deferred schema factory for recursive / mutually recursive structures (comment trees, categories).
-
Factory result is cached after first resolve.
-
compile()does not expand lazy nodes (avoids stack overflow on recursive graphs). -
Implements
AsyncValidatorand forwards to async inners when needed.late final Validator<Map<String, dynamic>> category; category = Flod.object({ 'name': Flod.string(), 'children': Flod.list(schema: Flod.lazy(() => category)), });
Added — inline message: on rules & refine #
-
Optional
message:on string/number/list rules and on.refine()/.refineAsync()/ctx.addIssue(...). -
Resolver priority: inline
message→ locale compiler. -
codeis still stored onFlodErrorfor logging / later i18n.Flod.string().min(8, message: 'Password too short'); Flod.string().email().refine( (e) => !e.endsWith('@tempmail.com'), message: 'Disposable emails are not allowed', );
Added — withDefaultFactory #
validator.withDefaultFactory(() => value)runs the factory on every missing/nullinput.
Fixed — mutable withDefault sharing #
withDefault([])/withDefault({})no longer return the same instance on every parse.Listvalues are cloned via.toList();Map<String, dynamic>viaMap<String, dynamic>.from.- Prefer
withDefaultFactoryfor nested mutable structures.
Docs #
- README documents coerce, lazy,
message:, safe defaults, leaf-level refine, UTF-16 length units, and refine chain short-circuit vssuperRefine. - Path format remains JSON-style indices:
items[1].qty(notitems.1.qty).
Migration (from 1.0.x) #
| Topic | Action |
|---|---|
Forms with TextFormField numbers/bools |
Switch fields to Flod.coerce.int() / .double() / .boolean() |
| Recursive schemas | Use Flod.lazy(() => …) with late final |
| Quick UI copy without i18n | Pass message: on rules |
| Mutable list/map defaults | Prefer withDefaultFactory; withDefault(list/map) is now safely cloned |
Existing Flod.int() / withDefault(0) call sites |
No change required |
No breaking signature removals — only additive APIs and safer default cloning.
1.0.4 #
Docs alignment release (paths, .secret() surface, Dio entry point). See package README.
1.0.3 #
Public-API hardening release. Fixes analyzer errors that appeared when consuming Flod from other apps (e.g. on ValidationException, abortEarly: true, Dio / DioException, FlodDefaultLocale) while following the documented README examples.
Fixed — public exports (package:flod/flod.dart) #
ValidationExceptionis now exported from the main library barrel.- Previously the class lived only under
lib/src/validators/exception_validator/validator_exception.dartand was used internally byparse/parseAsync/JsonGuard.parseJsonOrThrow/ Dio interceptor. - Consumers could not write
on ValidationException catch (e)afterimport 'package:flod/flod.dart'— the analyzer reportednon_type_in_catch_clause/undefined_class. - Examples and tests that imported the private
src/path no longer need that workaround; they use the public export.
- Previously the class lived only under
FlodDefaultLocaleis now exported from the main library barrel.- Previously only reachable via
lib/src/i18n/default_locale.dart. - Documented i18n setup (
return FlodDefaultLocale.compile(code, params)) now type-checks for downstream packages without private imports.
- Previously only reachable via
Fixed — abortEarly on the Parse API #
ValidatorExtensions.safeParse,parse,safeParseAsync, andparseAsyncnow accept an optional named parameter{bool? abortEarly}.- The flag is forwarded into
Validator.validate/AsyncValidator.validateAsync, matching:- schema-level
stopOnFirstError()/ objectabortEarly, and - the README example
schema.safeParse(data, abortEarly: true).
- schema-level
- Before this release, calling
safeParse(..., abortEarly: true)failed withundefined_named_parametereven though low-levelvalidate(..., abortEarly: …)already supported it. - Added a regression test: per-call
abortEarly: truereturns a single error on multi-field object failure (same behavior asstopOnFirstError()).
Fixed — Dio integration entry point (package:flod/dio.dart) #
- Re-exports the entire
package:dio/dio.dartsurface alongsideFlodValidateInterceptor. - A single
import 'package:flod/dio.dart'now resolvesDio,DioException,Interceptor,Response, etc., so handler code can catch validation failures without a separate Dio import:} on DioException catch (e) { if (e.error is ValidationException) { /* ... */ } } - Before this release, importing only
package:flod/dio.dartleftDio/DioExceptionundefined (undefined_function/undefined_class/non_type_in_catch_clause).
Changed — docs & examples #
- README entry-points table documents the new exports and Dio re-export.
- Parse / JsonGuard / Dio / i18n sections clarify public types and
parseJsonvsparseJsonOrThrow. - Package examples (
example/flod_example.dart,example/high_ex.dart) and tests no longer import privatesrc/paths forValidationException.
Migration (from ≤ 1.0.2) #
| Before (broken / private) | After (1.0.3) |
|---|---|
import '.../src/.../validator_exception.dart' |
import 'package:flod/flod.dart' — use ValidationException |
import '.../src/.../default_locale.dart' |
import 'package:flod/flod.dart' — use FlodDefaultLocale |
schema.stopOnFirstError() only for abort |
also safeParse(data, abortEarly: true) / parse(..., abortEarly: true) |
import 'package:dio/dio.dart' + package:flod/dio.dart |
import 'package:flod/dio.dart' alone is enough |
No breaking changes to existing method signatures beyond adding optional named parameters (abortEarly). Existing call sites continue to compile.