Feb 23, 2017 · 1 min read
I’m happy you found the article useful! I wouldn’t implement lerp using a factory constructor. Three reasons:
- It breaks with a Flutter SDK convention.
- It forces you to type
newwhenever you use it. - More importantly, there are cases where you need to return
nullfromlerp, for example if bothbeginandendarenull. I’ll return to the meaning of this in part two; suffice it to say thatColor.lerpinterprets anullend-point as a completely transparent color, and returnsnullwhen both end-points arenull. Factory constructors allow returningnull, but it doesn’t strike me as a particularly good practice. Maybe I’m just still too much of a Java guy, but an expression likenew Bar.lerp(...)screams “not null” to me.Bar.lerp(...)does not.
Thanks again for reading and commenting.
