'How to plot a function with canvas in Flutter & Dart

I want to plot a function with canvas in Flutter/Dart. Let's say we have an expression like that: y = 2x^2 + 4x. I have already tried drwaing a lot of little filled circles one near to another and this gives to me the desidered output. But I'm still searching for a more professional and right way to do that. Any help will be very appreciated, thank you!



Solution 1:[1]

If you want a fancy chart I would recommend fl_chart package. You could precalculate a list of values from your function and let fl_chart display them.

You could also use the CustomPaint widget and a CustomPainter to draw these values in different ways. You could simply draw a line from the current point to the next point which results in a (possibly not smooth) graph. Or add them to a curve with some bezier like interpolation to get a smooth graph without increasing the samples to much.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 MindStudio