4Q-s-r-o / signature

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

Flutter Web toPngBytes failing #27

Closed leonardarnold closed 4 years ago

leonardarnold commented 4 years ago

Image.toByteData is not supported in Flutter for Web The byte generation is failing on flutter web. I need a solution which works equally for web and the other platforms.

I managed it to get it work by using the package image: https://pub.dev/packages/image

It doesn't feel so right: For flutter web the signature points get redrawn with the image package (I did it almost equally how you did with the normal canvas). So it feels a bit duplicated and with an additional package, but maybe it's a starting point.

I am using Flutter Channel dev, 1.20.0-1.0.pre

Error: Exception: operation failed
    at Object.createErrorWithStack (http://localhost:59763/dart_sdk.js:4479:12)
    at Object._rethrow (http://localhost:59763/dart_sdk.js:37395:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:59763/dart_sdk.js:37389:13)
    at Object._microtaskLoop (http://localhost:59763/dart_sdk.js:37221:13)
    at _startMicrotaskLoop (http://localhost:59763/dart_sdk.js:37227:13)
    at http://localhost:59763/dart_sdk.js:32849:9Error: Exception: Image.toByteData is not supported in Flutter for Web
    at Object.throw_ [as throw] (http://localhost:59763/dart_sdk.js:4465:11)
    at Object.futurize (http://localhost:59763/dart_sdk.js:166948:17)
    at _engine.HtmlImage.new.toByteData (http://localhost:59763/dart_sdk.js:142412:22)
    at signature.SignatureController.new.toPngBytes (http://localhost:59763/packages/signature/signature.dart.lib.js:792:34)
    at toPngBytes.next (<anonymous>)
    at http://localhost:59763/dart_sdk.js:37106:33
    at _RootZone.runUnary (http://localhost:59763/dart_sdk.js:36960:58)
    at _FutureListener.thenAwait.handleValue (http://localhost:59763/dart_sdk.js:32047:29)
    at handleValueCallback (http://localhost:59763/dart_sdk.js:32594:49)
    at Function._propagateToListeners (http://localhost:59763/dart_sdk.js:32632:17)
    at _Future.new.[_completeWithValue] (http://localhost:59763/dart_sdk.js:32475:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:59763/dart_sdk.js:32497:35)
    at Object._microtaskLoop (http://localhost:59763/dart_sdk.js:37221:13)
    at _startMicrotaskLoop (http://localhost:59763/dart_sdk.js:37227:13)
    at http://localhost:59763/dart_sdk.js:32849:9
MartinHlavna commented 4 years ago

Fixed by #28