@@ -9,7 +9,15 @@ import 'package:signature/signature.dart';
99class FormBuilderSignaturePad extends FormBuilderField <Uint8List > {
1010 /// Controls the value of the signature pad.
1111 ///
12- /// If null, this widget will create its own [TextEditingController] .
12+ /// If null, this widget will create its own [SignatureController] .
13+ ///
14+ /// If your controller has the "onDrawEnd" method, your method will be executed first and then the values will be saved in the form field
15+ /// _controller.onDrawEnd = () async {
16+ /// onDrawEnd?.call();
17+ /// requestFocus();
18+ /// final val = await _getControllerValue();
19+ /// didChange(val);
20+ /// };
1321 final SignatureController ? controller;
1422
1523 /// Width of the canvas
@@ -135,21 +143,24 @@ class FormBuilderSignaturePadState
135143 void initState () {
136144 super .initState ();
137145 _controller = widget.controller ?? SignatureController ();
138- _controller.addListener (() async {
146+
147+ final onDrawEnd = _controller.onDrawEnd;
148+
149+ _controller.onDrawEnd = () async {
150+ onDrawEnd? .call ();
139151 requestFocus ();
140152 final val = await _getControllerValue ();
141153 didChange (val);
142- });
154+ };
155+
143156 SchedulerBinding .instance.addPostFrameCallback ((Duration duration) async {
144157 // Get initialValue or if points are set, use the points
145158 didChange (initialValue ?? await _getControllerValue ());
146159 });
147160 }
148161
149162 Future <Uint8List ?> _getControllerValue () async {
150- return await _controller.toImage () != null
151- ? await _controller.toPngBytes ()
152- : null ;
163+ return await _controller.toPngBytes ();
153164 }
154165
155166 @override
0 commit comments