omarhurani / flutter_painter

A Flutter widget to draw scribbles and text on a background image or color 🎨
MIT License
139 stars 107 forks source link

feat!: polygon drawing + support flutter v3.22.3+ #46

Closed tsinis closed 1 month ago

tsinis commented 2 years ago

Hey @friebetill

Thanks for a great package! In this PR I'm introducing polygon drawing mode (drawing straight lines/shapes via taping on the screens (creating nodes that are connected between each tap). The biggest issue was the calculation of the centroid (of the shape) because the shape can be very complex, I tried different libraries (ports from JS plugins), but if we take into account that it must be calculated in 8ms in the runtime and also influenced by the stroke-width (of the outline, the package must be universal), so the fastest formula I've found was from the Wikipedia. The result is not "pixel-perfect" but is usually quite sufficient. Also, I've created this code to be compatible with both Flutter 2 and Flutter 3 (Google's recommended way). Thanks!

friebetill commented 2 years ago

Hey @tsinis, unfortunately I'm not the maintainer and can't help you with the merge. This is the responsibility of @omarhurani.

tsinis commented 2 years ago

Hey @tsinis, unfortunately I'm not the maintainer and can't help you with the merge. This is the responsibility of @omarhurani.

Hey @friebetill, yeah you are right, looks like I've accidentally confirmed the GitHub suggestion at @ mention menu. I'm very sorry for that and thanks for tagging the proper person.

RegisSaffi commented 1 year ago

Hi @tsinis , I tried your changes and it looks very helpful, but there are some changes I would suggest:

tsinis commented 1 year ago

Hi @tsinis , I tried your changes and it looks very helpful, but there are some changes I would suggest:

  • Ability to close the path: Currently you just draw and the path never closes.
  • Ability to turn the drawn polygon into a selectable drawable: This might be a bit complicated but it would be very helpful, like when the path closes, I should be able to select the drawn polygon (The same way I do with other drawables)

Hey @RegisSaffi

I'm glad you like it! It's like half a year ago, but I'm not sure I understand what you mean, because the feature can handle both cases, with polygon draw you can do both:

Please check the video from the example (it's already there, in this feature branch): https://user-images.githubusercontent.com/52065414/234945740-afabffe2-ed12-4f6a-83e8-27c3a3db9e0a.mp4

RegisSaffi commented 1 year ago

Hi @tsinis , I guess I did not try everything, Am definitely gonna check it out, but am also wondering why this hasn't been merged yet??

tsinis commented 1 year ago

Hi @tsinis , I guess I did not try everything, Am definitely gonna check it out, but am also wondering why this hasn't been merged yet??

You better ask @omarhurani :)

hupo376787 commented 1 year ago

Hi, @tsinis. I found you created a great tool. I used C# and developed a polygon tool, it is more clear and intuitive. I think @RegisSaffi needs polygon's behavior like below.

GIF 2023-8-30 20-39-21

tsinis commented 1 year ago

Hey @hupo376787 nice I see, congratz!

hupo376787 commented 1 year ago

But I'm new to flutter, read dart makes me confuse. So if you can make some changes to polygon, it's will be a great job. Thanks.

tsinis commented 1 year ago

@hupo376787 TBH, I don't think this PR will be ever merged. There were no updates in this repo for a year and a half, so I am also not interested in maintaining this code since there is no interest from the author side.

hupo376787 commented 1 year ago

@tsinis Indeed. The author may focus on some other important things.

tsinis commented 4 months ago

I have upgraded this branch to the latest stable version of Flutter, it should fix https://github.com/omarhurani/flutter_painter/issues/43

KartikGavhale commented 1 month ago

@tsinis i tried using your code. but im getting few error one of which is Offset argument contained a NaN value. 'dart:ui/painting.dart': Failed assertion: line 36 pos 10: '' Do you know whats wrong with the code im trying to use the nodepoygon shapefactory