is there a way to use some variable or any holder to store constructor parameters,
to be able to pass them to multiple constructors without repeating the values?
I think its possible if the constructor has only positional parameters (no named parameters).
var parametersHolder={
named1: "str",
named2: "lorem",
};
// normal usage
constructorA(named1: "str", named2: "lorem");
constructorB(named2: "lorem",named1: "str" );
my question is how to do the following in dart:
constructorA(parametersHolder);
constructorB(parametersHolder);
so is that achievable ?
Thanks
2
Answers
You can define a class to hold your parameters like this:
If you really want, you could use
Function.apply
with a constructor tear-off:Note that doing this sacrifices compile-time type-safety.