RomanBase / hand_signature

A Flutter plugin providing signature pad for drawing smooth signatures.
https://pub.dev/packages/hand_signature
MIT License
108 stars 25 forks source link

'<optimized out>': Offset argument contained a NaN value. #41

Closed LokeshReddy63 closed 10 months ago

LokeshReddy63 commented 1 year ago

Do i need to do anything to get the image file adding my code snippet. i am not adding any HandSignature in the widget, i was storing the signature map data in the state and when ever i wanted i used a handsignature controller and tried to create an image that has to be added to a PDF Image.

My code :

HandSignatureControl control = HandSignatureControl();
  HandSignature(
    control: control,
  );
  if (resume.signature != null) {
    resume.signature!.forEach(
      (key, value) => print(key + " :: " + value.toString()),
    );
    control.importData(resume.signature!.cast<dynamic, dynamic>());
  }
  ByteData? image = await control.toImage();
  Uint8List? imageData;
  final imagePDF;
  if (image != null) {
    imageData = image.buffer.asUint8List();
    imagePDF = MemoryImage(imageData);
  } else {
    imagePDF = null;
  }

ERROR :

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'dart:ui/painting.dart': Failed assertion: line 36 pos 10: '<optimized out>': Offset argument contained a NaN value.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2      _offsetIsValid (dart:ui/painting.dart:36:10)
#3      _NativePath.arcToPoint (dart:ui/painting.dart:2973:12)
#4      CubicArc.path (package:hand_signature/src/signature_control.dart:413:7)
#5      PathSignaturePainter.paint.<anonymous closure>.<anonymous closure> (package:hand_signature/src/signature_painter.dart:90:33)
#6      List.forEach (dart:core-patch/growable_array.dart:416:8)
#7      PathSignaturePainter.paint.<anonymous closure> (package:hand_signature/src/signature_painter.dart:88:21)
#8      List.forEach (dart:core-patch/growable_array.dart:416:8)
#9      PathSignaturePainter.paint (package:hand_signature/src/signature_painter.dart:87:15)
#10     HandSignatureControl.toPicture (package:hand_signature/src/signature_control.dart:1197:13)
#11     HandSignatureControl.toImage (package:hand_signature/src/signature_control.dart:1216:25)
#12     GenerateFresherPdf (package:resume/helper/pdf/fresher_pdf_helper.dart:35:35)
#13     _PdfPreviewPageState.build (package:resume/pages/create_resume/pdf_preview.dart:51:25)
#14     StatefulElement.build (package:flutter/src/widgets/framework.dart:5409:27)
#15     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5297:15)
#16     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
#17     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#18     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2779:19)
#19     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:916:21)
#20     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:360:5)
#21     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
#22     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9)
#23     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:952:7)
#24     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
#25     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#26     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#27     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)

Reloaded 28 of 2382 libraries in 758ms (compile: 375 ms, reload: 147 ms, reassemble: 188 ms).

======== Exception caught by printing ==============================================================
The following assertion was thrown while generating a PDF:
Offset argument contained a NaN value.
'dart:ui/painting.dart':
Failed assertion: line 36 pos 10: '<optimized out>'

When the exception was thrown, this was the stack: 
#2      _offsetIsValid (dart:ui/painting.dart:36:10)
#3      _NativePath.arcToPoint (dart:ui/painting.dart:2973:12)
#4      CubicArc.path (package:hand_signature/src/signature_control.dart:413:7)
#5      PathSignaturePainter.paint.<anonymous closure>.<anonymous closure> (package:hand_signature/src/signature_painter.dart:90:33)
#6      List.forEach (dart:core-patch/growable_array.dart:416:8)
#7      PathSignaturePainter.paint.<anonymous closure> (package:hand_signature/src/signature_painter.dart:88:21)
#8      List.forEach (dart:core-patch/growable_array.dart:416:8)
#9      PathSignaturePainter.paint (package:hand_signature/src/signature_painter.dart:87:15)
#10     HandSignatureControl.toPicture (package:hand_signature/src/signature_control.dart:1197:13)
#11     HandSignatureControl.toImage (package:hand_signature/src/signature_control.dart:1216:25)
#12     GenerateFresherPdf (package:resume/helper/pdf/fresher_pdf_helper.dart:35:35)
#13     _PdfPreviewPageState.build (package:resume/pages/create_resume/pdf_preview.dart:51:25)
#14     StatefulElement.build (package:flutter/src/widgets/framework.dart:5409:27)
#15     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5297:15)
#16     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
#17     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#18     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2779:19)
#19     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:916:21)
#20     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:360:5)
#21     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
#22     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9)
#23     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:952:7)
#27     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
(elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)
PageFormat: "PdfPageFormat 612.0x792.0 margins:72.0, 72.0, 72.0, 72.0"
====================================================================================================
LokeshReddy63 commented 1 year ago

With a threshold of >1 tried but not solving it

RomanBase commented 11 months ago

Hey, sorry for late answer. Problem can be, that you don't have specified Canvas size. I guess you need to call notifyDimension before exporting image (toImage).

Please also check your export data (toMap) if there is bounds specified with non-zero values, so you can set control (and canvas) dimensions to this bounds.