Signature

Signature Widget

The Signature widget allows users to capture handwritten signatures directly within your application. It provides a canvas where users can draw their signature using touch or mouse input. The widget is highly customizable, enabling you to adjust its appearance and behavior to suit your application's needs.

Key Properties and Features

  • Pen Customization: Adjust the pen color (penColor), stroke width (penStrokeWidth), stroke cap (strokeCap), and stroke join (strokeJoin) to customize the drawing experience.

  • Background Customization: Set the background color of the signature pad using backgroundColor.

  • Value Handling: The value property holds the signature data encoded as a Base64 string. This can be used to retrieve or set the signature.

  • Disabling Input: Use the disabled property to prevent users from drawing on the signature pad, useful for displaying a previously captured signature.

  • Export Options: Customize the colors used when exporting the signature image with exportBackgroundColor and exportPenColor.

  • Getters: Access additional data through getters like isEmpty, getSignatureBytes, getSignatureSVG, and getSignatureJPG.

  • Events: The onChange event is triggered whenever the signature pad's content changes, allowing you to react to user input.

  • Methods: The clear() method allows you to programmatically clear the signature pad.

Explanation of Examples

  • Basic Signature Pad: Demonstrates a simple signature pad with customized pen color and stroke width. An onChange event is defined to execute code whenever the signature changes.

  • Signature Pad with Clear Button and Export: Includes a signature pad with buttons to clear the signature and to save/export the signature data. The clear() method resets the pad. The value property retrieves the Base64-encoded signature data for storage or processing.

Properties

PropertyTypeDescription
idstringUnique identifier for the widget.
valuestringThe current value of the signature, encoded as a Base64 string. Can be used to retrieve or set the signature.
disabledbooleanIf true, the signature pad is disabled and the user cannot draw. Default is false.

Events

EventDescription
onChangeTriggered whenever the signature pad's content changes. Use this event to execute actions or code in response to user input.

Methods

MethodDescription
clear()Clears the signature pad programmatically.

Getters

These properties can be accessed to retrieve additional information or data from the signature widget.

GetterTypeDescription
isEmptybooleanReturns true if the signature pad is empty, false otherwise.
valuestringRetrieves the current signature data as a Base64-encoded string.
getSignatureBytesUint8ListRetrieves the signature data as raw bytes (PNG format).
getSignatureSVGSvgPictureRetrieves the signature as an SVG image.
getSignatureJPGui.ImageRetrieves the signature as a ui.Image (for advanced use cases).

Styles

Dimension and Positioning

PropertyTypeDescription
widthintegerThe width of the signature pad. Can be a number (pixels) or a percentage string (e.g., "100%").
heightintegerThe height of the signature pad. Can be a number (pixels) or a percentage string (e.g., "100%").
marginintegerThe margin around the signature pad. Supports shorthand notation like "10 5 10".
paddingintegerThe padding inside the signature pad. Supports shorthand notation like "10 5 10".
alignmentstringAlignment of the widget within its parent. Possible values: "left", "right", "center", "top", "bottom", "stretch".

Appearance

PropertyTypeDescription
penColorColorThe color of the pen used for drawing the signature. Accepts color names, hex codes, or RGB values. Default is "black".
penStrokeWidthnumberThe stroke width of the pen used for drawing the signature. Must be a positive number. Default is 3.0.
backgroundColorColorThe background color of the signature pad. Accepts color names, hex codes, or RGB values. Default is "#CCCCCC".
strokeCapstringThe stroke cap style for the pen. Determines how the ends of lines are drawn. Possible values are "butt", "round", "square". Default is "butt".
strokeJoinstringThe stroke join style for the pen. Determines how two connecting lines are joined. Possible values are "miter", "round", "bevel". Default is "miter".
exportBackgroundColorColorThe background color used when exporting the signature image. If not specified, defaults to the backgroundColor.
exportPenColorColorThe pen color used when exporting the signature image. If not specified, defaults to the penColor.
boxShadowobjectThe box shadow styling for the signature pad. See BoxShadow properties below.
clipContentbooleanIf true, clips the content inside the signature pad. Default is false.
visiblebooleanControls the visibility of the widget. Default is true.
elevationintegerThe elevation (shadow depth) of the widget. Accepts values from 0 to 24.
elevationShadowColorColorThe color of the elevation shadow. Accepts color names, hex codes, or RGB values.
elevationBorderRadiusintegerThe border radius for the elevation shadow.

BoxShadow

PropertyTypeDescription
colorColorThe color of the shadow. Accepts color names, hex codes, or RGB values.
offsetXintegerThe horizontal offset of the shadow.
offsetYintegerThe vertical offset of the shadow.
blurRadiusintegerThe blur radius of the shadow.
spreadRadiusintegerThe spread radius of the shadow.

Box Styles (Inherited)

This widget also inherits these styles:

PropertyTypeDescription
margininteger/stringMargin with CSS-style notation (1 to 4 integers) e.g. margin: 5 20 5
paddinginteger/stringPadding with CSS-style notation (1 to 4 integers) e.g. padding: 5 20 5
backgroundColorColorThe background color of this widget.
backgroundImageBackgroundImageThe background image of this widget.
backgroundGradientGradientThe background gradient of this widget.
borderBorderThe border of this widget.
shadowShadowThe shadow of this widget
clipContentbooleanSome widgets (such as Image) may bleed through the container when borderRadius is set. Use this to apply a clipping to ensure this does not happen.
widthintegerThe width of this widget.
heightintegerThe height of this widget.
borderRadiusstring or integerThe border radius of the widget. This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0.
borderColorinteger or stringSets the border color, starting with '0xFF' for full opacity. Possible values: transparent, black, blue, white, red, grey, teal, amber, pink, purple, yellow, green, brown, cyan, indigo, lime, orange.
borderWidthintegerThickness of the border. Minimum value should be 0.
shadowColorinteger or stringSets the box shadow color starting with '0xFF' for full opacity. Possible values: transparent, black, blue, white, red, grey, teal, amber, pink, purple, yellow, green, brown, cyan, indigo, lime, orange.
shadowOffsetarrayThe values in the array define the horizontal and vertical offset of the shadow. Example: if the shadowOffset is set to [2, 4], the shadow will be offset by 2 pixels horizontally and 4 pixels vertically from its original position.
shadowRadiusstring or integerThe border radius of the widget. This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0.
shadowStylestringThe blur style to apply on the shadow: normal, solid, outer, inner.

Base Styles (Inherited)

This widget also inherits these base styles:

PropertyTypeDescription
visiblebooleanToggle a widget visibility on/off. Note that an invisible widget will not occupy UI space, unless the visibilityTransitionDuration is specified.
visibilityTransitionDurationnumberSpecify the duration in seconds when a widget animates between visible and not visible state. Note that setting this value will cause the widget to still occupy the UI space even when it is not visible.
elevationintegerThe z-coordinate at which to place this material relative to its parent. A non-zero value will show a shadow, with its size relative to the elevation value. (Minimum: 0, Maximum: 24)
elevationShadowColorColorThe shadow color for the elevation.
elevationBorderRadiusinteger / stringIf the widget has a borderRadius, this should be changed to have the same value. Use with CSS-like notation (1 to 4 integers).
alignmentAlignmentAlign this widget relative to its parent.
stackPositionTopintegerThe distance of the child's top edge from the top of the stack. This is applicable only for Stack's children.
stackPositionBottomintegerThe distance that the child's bottom edge from the bottom of the stack. This is applicable only for Stack's children.
stackPositionLeftintegerThe distance that the child's left edge from the left of the stack. This is applicable only for Stack's children.
stackPositionRightintegerThe distance that the child's right edge from the right of the stack. This is applicable only for Stack's children.
captureWebPointerbooleanApplicable for Web only. When overlaying widgets on top of certain HTML container (e.g., Maps), the mouse click is captured by the HTML container, causing issue interacting with the widget. Use this to capture and maintain the mouse pointer on your widget.