0

Please tell me, is it possible to locate list of widgets along the curve? Like on picture, Let's say teeth are widgets.

fartem
  • 2,361
  • 2
  • 8
  • 20

1 Answers1

0

If you don't want to use Stack, then you might try out the CustomPaint widget and drawing in flutter with paths. There's a tutorial to painting: https://medium.com/flutter-community/paths-in-flutter-a-visual-guide-6c906464dcd0

However, painting is a limited thing and if you have an actual widgets that need to be fully responsive and act as a widgets, you need to use Stack with Positioned. That's the only way to go.

Also, in this question about animating along the curve in flutter you can find some code examples that use both: painting and stack and even animate that. Possibly the most useful code from there is calculating the position of an object that you want to place along some curve:

Offset calculate(path, along) {
    PathMetrics pathMetrics = path.computeMetrics();
    PathMetric pathMetric = pathMetrics.elementAt(0);
    along = pathMetric.length * along;
    Tangent pos = pathMetric.getTangentForOffset(along);
    return pos.position;
  }

In above example you need to have some Path which is a representation of some curve. For example you can get one like this:

Path getPath(){
    Size size = Size(300,300);
    Path path = Path();
    path.moveTo(0, size.height / 2);
    path.quadraticBezierTo(size.width / 2, size.height, size.width, size.height / 2);
    return path;
  }

then you give this path and some along, which is number between 0 and 1, which represents beginning and ending of this curve and you give it to the calculate, which return and Offset, which you can use in your Positioned inside your Stack:

Positioned(
            top: calculate(path, along).dy,
            left: calculate(path, along).dx,
            child: ...

When you only want some shapes to be drawn on a screen then you can use simply painting with CustomPaint widget, but this objects won't be widgets