fixedLengthList - freezed & dart

65 Views Asked by At

How to make fixedLengthList in class model using @freezed?

@freezed
class Example with _$Example {
  factory Example({
    List<int> example, // this list should be max 5 positions, not more
  }) = _Example;
}
1

There are 1 best solutions below

0
On

You can do it like so:

@freezed
class Example with _$Example {
  @Assert('example.length <= 5', 'this list should be max 5 positions, not more')
  factory Example({
    List<int> example
  }) = _Example;
}