4Q-s-r-o / signature

Flutter plugin that creates a canvas for writing down a signature
MIT License
252 stars 83 forks source link

Import a previous signature #17

Closed SmartInovacoesTecnologias closed 2 years ago

SmartInovacoesTecnologias commented 4 years ago

how can i open a previous signature from bytes stored in a blob column in database?, Im expecting something like _controller.fromBytes(Uint8List), but, i just found the _controller.points(List<Point>) but i cant figure out how store this on db

MartinHlavna commented 4 years ago

I am sorry but this is not supported. It would require a way to reverse the export process and get points vector from raster.

IMHO I could not think of use case where I would need to edit signature. If you want to display stored data, you should display it as Image.

khurana3192 commented 3 years ago

I was able to export points to a JSON. Remember that you need to store offsets's dx and dy along with PointType (move or tap).

My JSON that was stored on server looked something like this [[123.55,66.77,"tap"], [123.55,66.77,"move"],...]

I then used this data to create a List of Points and feed into the controller and it worked

vinnchan commented 3 years ago

I was able to export points to a JSON. Remember that you need to store offsets's dx and dy along with PointType (move or tap).

My JSON that was stored on server looked something like this [[123.55,66.77,"tap"], [123.55,66.77,"move"],...]

I then used this data to create a List of Points and feed into the controller and it worked

Hi Khurana, can you elaborate more about how you retrieve from server and feed into controller, thank you

hortegag91 commented 3 years ago

I was able to export points to a JSON. Remember that you need to store offsets's dx and dy along with PointType (move or tap). My JSON that was stored on server looked something like this [[123.55,66.77,"tap"], [123.55,66.77,"move"],...] I then used this data to create a List of Points and feed into the controller and it worked

Hi Khurana, can you elaborate more about how you retrieve from server and feed into controller, thank you

I save it like this var json = jsonEncode(_controller.points .map((e) => '${e.type},${e.offset.dx},${e.offset.dy}') .toList()); and save it on server

And when i fetch that json from server set the points like this List<dynamic> points = jsonDecode(json); points.forEach((element) { List<String> d = element.toString().split(r','); _controller.addPoint(Point( Offset(double.parse(d[1]), double.parse(d[2])), d[0] == 'PointType.tap' ? PointType.tap : PointType.move, )); });

Im sure they are better ways but i make it fast

MartinHlavna commented 3 years ago

If needed we could add some utilities to aid in json conversion.

Jackyto commented 2 years ago

And when i fetch that json from server set the points like this List<dynamic> points = jsonDecode(json); points.forEach((element) { List<String> d = element.toString().split(r','); _controller.addPoint(Point( Offset(double.parse(d[1]), double.parse(d[2])), d[0] == 'PointType.tap' ? PointType.tap : PointType.move, )); });

This lane saved my day, was trying to find how to display a recorded signature, thank you mate !