dnfield / dart_path_parsing

MIT License
27 stars 8 forks source link

Canvas.drawPath problem #1

Open privateGenish opened 5 years ago

privateGenish commented 5 years ago

how am i suppose to draw the path if it's a proxy path?

class BadPath extends parse.PathProxy {
  @override
  void close() {}
  @override
  void moveTo(double x, double y) {}
  @override
  void cubicTo(
      double x1, double y1, double x2, double y2, double x3, double y3) {}
  @override
  void lineTo(double x, double y) {}
}

class TopDecoration extends CustomPainter {
  final String topDecoration =
      'M832.165,316.589c-73.605,86.636-219.245,55.9-375,50.662-.073.031.021-271.25.021-271.25H832.165Z';
  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint();
    BadPath path = BadPath();

    parse.writeSvgPathDataToPath(topDecoration, path);
    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    // TODO: implement shouldRepaint
    return false;
  }
}
dnfield commented 5 years ago

Like this:

class BadPath extends parse.PathProxy {
   Path path = Path();
  @override
  void close() { path.close() }
  @override
  void moveTo(double x, double y) { path.moveTo(x, y); }
  @override
  void cubicTo(
      double x1, double y1, double x2, double y2, double x3, double y3) { path.cubicTo(x1, y1, x2, y2, x3, y3); }
  @override
  void lineTo(double x, double y) { path.lineTo(x, y); }
}

class TopDecoration extends CustomPainter {
  final String topDecoration =
      'M832.165,316.589c-73.605,86.636-219.245,55.9-375,50.662-.073.031.021-271.25.021-271.25H832.165Z';
  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint();
    BadPath path = BadPath();

    parse.writeSvgPathDataToPath(topDecoration, path);
    canvas.drawPath(path.path, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    // TODO: implement shouldRepaint
    return false;
  }
}

There are other probably cleaner ways, but that's the idea.

privateGenish commented 5 years ago

thank you so much! this is a great rep!

privateGenish commented 5 years ago

i used the same code as you posted, yet flutter dont paint it... i added a color property and still no paint.