WebsiteUrlPattern class
WebsiteUrlPattern is a specialized EntryPattern metadata annotation designed to validate whether a string conforms to a standard web URL format.
It provides a declarative mechanism for Universal Resource Locator
Validation, allowing the cell.core framework and code generation tools
(like build_model) to ensure that user-provided links and web endpoints
adhere to structural internet standards before being accepted into the
reactive graph.
When to use
Use this on String fields that store URLs to ensure they are valid
web addresses before processing (e.g., opening in a browser, fetching data).
How it works
By default, it uses a regex that checks for http:// or https://, domain, and optional path. You can customise the pattern if needed.
Examples
1. Standard Link Validation
@WebsiteUrlPattern()
final String portfolioUrl;
2. Custom Pattern or Nullability
@WebsiteUrlPattern(
pattern: r'^https:\/\/corporate\.com\/[a-z]+$',
allowNull: true
)
final String? officialPage;
Parameters
- pattern: The regular expression string. Defaults to a robust, common
URL validation pattern:
^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$. - caseSensitive: Defaults to
false, as URLs are generally treated as case-insensitive for validation purposes. - allowEmpty: Defaults to
false. - allowNull: Defaults to
true, facilitating optional URL fields.
Note: The default regex is designed for general-purpose web addresses. For strict adherence to specific RFCs or to require mandatory subdomains/paths, consider a custom pattern.
- Inheritance
-
- Object
- TestRule<
Never> - EntryPattern
- WebsiteUrlPattern
Constructors
- WebsiteUrlPattern({String pattern = r'^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$', bool caseSensitive = false, bool allowEmpty = false, bool allowNull = true})
-
Creates a WebsiteUrlPattern rule.
const
Properties
- allowEmpty → bool
-
If
true, empty strings ('') are considered valid.finalinherited - allowNull → bool
-
If
true,nullvalues are considered valid.finalinherited - caseSensitive → bool
-
Whether the pattern matching should be case-sensitive.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- pattern → String
-
The regular expression pattern used to validate the input string.
finalinherited
- purity → Purity
-
A rule's purity. Defaults to Purity.pure; rules that perform
external I/O must override — a rule that reads external state (a
clock, an environment variable, a read-only database) to
Purity.readOnlyExternal, a rule that mutates external state (rare;
mostly misuse) to Purity.effectful and be journalled.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- version → String
-
A rule's version. Defaults to
'0.0.0'; subclasses should override with a stable string. See Receptor.version.no setterinherited
Methods
-
call(
dynamic object, {covariant Never host, dynamic arguments}) → FutureOr< bool> -
Executes the validation against the provided
object.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator +(
covariant TestRule< Never> other) → TestRule<Never> -
Composes two TestRule instances into a sequential Validation Pipeline.
inherited
-
operator ==(
Object other) → bool -
The equality operator.
inherited