By Alvin Alexander. Last updated: March 15, 2022
As a quick note, this Flutter/Dart example shows a class constructor that uses named parameters:
class Properties {
int minAnimationDuration;
int maxAnimationDuration;
int imageFadeDuration;
int maxScale;
Properties({
this.minAnimationDuration = 4,
this.maxAnimationDuration = 10,
this.imageFadeDuration = 5,
this.maxScale = 2
});
}
final props = Properties(
minAnimationDuration: 4,
maxAnimationDuration: 10,
imageFadeDuration: 5,
maxScale: 2
);
There may be other ways to create a class constructor with named parameters in Dart, especially when you’re using nullable parameters, but for today, I can confirm that this works for me.