FieldLike<T> class abstract

Superclass for Field, SetField, and ListField.

Comparison to code generation

  • Easier to use. Field<T> may be simpler for developers than setting up code generation correctly. See the example below.
  • Worse performance.
    • Use of Field<T> raises memory consumption. It slows down allocations, memory accesses, and garbage collection. But avoid premature optimization! The performance impact is unlikely to be noticeable in typical business applications.

Example

The following example demonstrates use of Field, ListField, and SetField.

The relatively few lines of code gives you:

  • JSON serialization.
  • Protocol Buffers / GRPC serialization.
  • Database mapping.
  • Observability of both reads and writes (see ReactiveSystem).
import 'package:kind/kind.dart';

class Person extends Entity {
   static final EntityKind<Person> kind = EntityKind<Person>(
     name: 'Person',
     define: (c) {
       // You could also use shorthand: `requiredString(...)`
       c.addProp(Prop<Person, String>(
         id: 1,
         name: 'name',
         field: (e) => e.name,
         kind: StringKind(
           maxLengthInUtf8: 80,
         ),
       ));
       // You could also use shorthand: `optionalDate(...)`
       c.addProp(Prop<Person, Date?>(
         id: 2,
         name: 'dateOfBirth',
         field: (e) => e.dateOfBirth,
         kind: DateKind().toNullable(),
       ));
       // You could also use shorthand: `requiredList(...)`
       c.addProp(Prop<Person, List<String>>(
         id: 3,
         name: 'favoriteFoods',
         field: (e) => e.favoriteFoods,
         kind: ListKind(
           itemsKind: StringKind(
             maxLengthInUtf8: 80,
           ),
         ),
       ));
       // You could also use shorthand: `requiredSet(...)`
       c.addProp(Prop<Person, Set<Person>>(
         id: 4,
         name: 'friends',
         field: (e) => e.friends,
         kind: SetKind<Person>(
           itemsKind: Person.kind,
         ),
       ));
     },
  );

  /// Full name.
  late final Field<String> name = Field<String>(this);

  /// Date of birth, if known.
  late final Field<Date?> dateOfBirth = Field<Date?>(this);

  /// Favorite foods (ordered by preference).
  late final ListField<Food> favoriteFoods = ListField<Food>(this);

  /// Friends (unordered).
  late final SetField<Person> friends = SetField<Person>(this);

  @override
  EntityKind<Person> getKind() => kind;
}
Implementers

Constructors

FieldLike(Entity $parent)

Properties

$additionalData Map<Object, Object>
Additional data about this reference.
getter/setter pair
$parent Entity
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getParentProp() Prop<dynamic, T>
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 ==(Object other) bool
The equality operator.
inherited