Dev Tools · 1h ago
Dart const constructors can bypass factory validation, warns developer
A developer discovered that public const constructors in Dart allow users to bypass factory validation, as seen in the instructor_dart package. The factory methods validate inputs like regex patterns, but the raw constructors skip those checks. The fix is non-trivial because const constructors cannot contain validation logic.
Meridian48 take
This is a subtle but important design gotcha for Dart library authors, though its impact is limited to packages that expose both factories and public constructors.
Read the full reporting
A public const constructor is the back door around your factory's validation →
DEV Community
dartvalidation