ReactiveSignature<T> constructor
- Key? key,
- String? formControlName,
- FormControl<
T> ? formControl, - Map<
String, ValidationMessageFunction> ? validationMessages, - ControlValueAccessor<
T, Uint8List> ? valueAccessor, - ShowErrorsFunction<
T> ? showErrors, - InputDecoration? decoration,
- SignatureController? controller,
- SignatureBuilder? signatureBuilder,
- Color backgroundColor = Colors.grey,
- double? width,
- double? height,
- Color penColor = Colors.black,
- Color exportBackgroundColor = Colors.blue,
- double penStrokeWidth = 3.0,
- List<
Point> ? points, - VoidCallback? onDrawStart,
- VoidCallback? onDrawMove,
- VoidCallback? onDrawEnd,
Creates a ReactiveSignature that contains a Signature
.
Can optionally provide a formControl
to bind this widget to a control.
Can optionally provide a formControlName
to bind this ReactiveFormField
to a FormControl
.
Must provide one of the arguments formControl
or a formControlName
,
but not both at the same time.
Can optionally provide a validationMessages
argument to customize a
message for different kinds of validation errors.
Can optionally provide a valueAccessor
to set a custom value accessors.
See ControlValueAccessor
.
Can optionally provide a showErrors
function to customize when to show
validation messages. Reactive Widgets make validation messages visible
when the control is INVALID and TOUCHED, this behavior can be customized
in the showErrors
function.
Example:
Binds a text field.
final form = fb.group({'email': Validators.required});
ReactiveSignature(
formControlName: 'email',
),
Binds a text field directly with a FormControl.
final form = fb.group({'email': Validators.required});
ReactiveSignature(
formControl: form.control('email'),
),
Customize validation messages
ReactiveSignature(
formControlName: 'email',
validationMessages: {
ValidationMessage.required: 'The email must not be empty',
ValidationMessage.email: 'The email must be a valid email',
}
),
Customize when to show up validation messages.
ReactiveSignature(
formControlName: 'email',
showErrors: (control) => control.invalid && control.touched && control.dirty,
),
For documentation about the various parameters, see the Signature
class
and Signature
, the constructor.
Implementation
ReactiveSignature({
super.key,
super.formControlName,
super.formControl,
super.validationMessages,
super.valueAccessor,
super.showErrors,
////////////////////////////////////////////////////////////////////////////
InputDecoration? decoration,
SignatureController? controller,
SignatureBuilder? signatureBuilder,
Color backgroundColor = Colors.grey,
double? width,
double? height,
this.penColor = Colors.black,
this.exportBackgroundColor = Colors.blue,
this.penStrokeWidth = 3.0,
this.points,
this.onDrawStart,
this.onDrawMove,
this.onDrawEnd,
}) : super(
builder: (field) {
final state = field as _ReactiveSignatureState;
final InputDecoration effectiveDecoration = (decoration ??
const InputDecoration())
.applyDefaults(Theme.of(state.context).inputDecorationTheme);
final child = Signature(
controller: state._signatureController,
width: width,
height: height,
backgroundColor: backgroundColor,
);
return InputDecorator(
decoration: effectiveDecoration.copyWith(
errorText: field.errorText,
enabled: field.control.enabled,
),
child: signatureBuilder?.call(
field.context, child, state._signatureController) ??
Row(
children: [
Expanded(child: child),
IconButton(
icon: const Icon(Icons.clear),
onPressed: () => state._signatureController.clear(),
)
],
),
);
},
);