@@ -9,7 +9,15 @@ import 'package:signature/signature.dart';
9
9
class FormBuilderSignaturePad extends FormBuilderField <Uint8List > {
10
10
/// Controls the value of the signature pad.
11
11
///
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
+ /// };
13
21
final SignatureController ? controller;
14
22
15
23
/// Width of the canvas
@@ -135,21 +143,24 @@ class FormBuilderSignaturePadState
135
143
void initState () {
136
144
super .initState ();
137
145
_controller = widget.controller ?? SignatureController ();
138
- _controller.addListener (() async {
146
+
147
+ final onDrawEnd = _controller.onDrawEnd;
148
+
149
+ _controller.onDrawEnd = () async {
150
+ onDrawEnd? .call ();
139
151
requestFocus ();
140
152
final val = await _getControllerValue ();
141
153
didChange (val);
142
- });
154
+ };
155
+
143
156
SchedulerBinding .instance.addPostFrameCallback ((Duration duration) async {
144
157
// Get initialValue or if points are set, use the points
145
158
didChange (initialValue ?? await _getControllerValue ());
146
159
});
147
160
}
148
161
149
162
Future <Uint8List ?> _getControllerValue () async {
150
- return await _controller.toImage () != null
151
- ? await _controller.toPngBytes ()
152
- : null ;
163
+ return await _controller.toPngBytes ();
153
164
}
154
165
155
166
@override
0 commit comments