'how give a Validator in a Class a value inside?

I have a prob with my Class Foo, I want to give my Validator a value from Class self. Anyone have an idea, how I can solve this?


@JsonSerializable()
class Foo {
   Foo({
    required this.userId, 
    required this.rangeWithValidator, 
    required this.enumFoo,
  }) {
    // Apply the validator
    _$assertFoo(this);
  }

  final String userId;
  final EnumFoo enumFoo;

  // Apply the `Min` validator
  @RangeValidator(minValue: 0, maxValue: 1, enumFoo: enumFoo) // <-- ERROR Arguments of a constant creation must be constant expressions. (Documentation)  Try making the argument a valid constant, or use 'new' to call the constructor.
  final num rangeWithValidator;


}

My Validator

class RangeValidator extends Validator {
  const RangeValidator({required this.minValue,  required this.maxValue, this. enumFoo});
  final num minValue;
  final num maxValue;
  final EnumFoo? enumFoo;

~ Foo ~
}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source