Syntax and Declaration
Records consist of a comma-delimited list of named or positional fields enclosed in parentheses.Record Expressions
A record expression creates a record value. Named fields use a colon syntax (name: value), while positional fields are inferred by their order.
Record Type Annotations
Record types are defined by a comma-delimited list of types enclosed in parentheses. Named fields are enclosed inside curly braces{} within the record type annotation.
Field Access
Record fields are accessed via built-in getters.- Named fields are accessed using the property name (e.g.,
.x). - Positional fields are accessed using the syntax
$<position>, starting at$1.
'last' is the second positional field, so it is accessed via $2, skipping the named fields.
Structural Typing and Equality
Records have value equality. Two records are considered equal if they have the same shape and their corresponding fields have equal values. The shape of a record is defined solely by:- The number of positional fields.
- The names of the named fields.
(int,) and (double,) share the same shape. Additionally, the order of named fields does not affect the record’s shape or equality.
Single-Field Records
To distinguish a record containing a single positional field from a standard parenthesized expression, a trailing comma is required in both the record expression and the type annotation.Destructuring
Records support pattern matching and destructuring, allowing values to be unpacked into local variables.Master Dart with Deep Grasping Methodology!Learn More





