Skip to content

Commit a2ad162

Browse files
Merge pull request #39 from ElAdrixHD/main
Fixed bad pad field performance on web.
2 parents 33ba0a4 + 2b8ea4a commit a2ad162

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
## [8.4.0] - 26-Oct-2022
1+
## [8.4.0] - 28-Oct-2022
22

33
* Set by default flex loose to `FormBuilderSearchableDropdown`
44
* Set show search field by default
55
* Added customization support for color picker field
66
* Bumped dependencies :
77
* `flutter_form_builder` from 7.3.1 to 7.7.0
88
* `dropdown_search` from 5.0.2 to 5.0.3
9+
* Performance improvement on FormBuilderSignaturePad on Web
910

1011
## [8.3.0] - 27-Jul-2022
1112

lib/src/fields/form_builder_signature_pad.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import 'package:signature/signature.dart';
99
class 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

Comments
 (0)