Want to efficiently initialize multiple final fields that depend on the same calculation in Dart? Calculate the values in a factory constructor:
1 2 3 4 5 6 7 8 9 10 |
class _IntegralCurve extends Curve { static double delta = 0.01; factory _IntegralCurve(Curve original) { final integral = calculateIntegral(original), final values = calculateNormalizedValues(original); return _IntegralCourve._(original, integral, values); } _IntegralCurve._(this.original, this.integral, this.values); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.