'fixedLengthList - freezed & dart
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;
}
Solution 1:[1]
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;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | atruby |