Skip to main content

MiCheckbox

The MiCheckbox component is a Flutter widget for creating interactive checkboxes with optional labels and action capabilities.

Overview

MiCheckbox extends MiStatelessWidget, serving as a customizable checkbox component. It allows users to toggle a boolean state, which can be linked to a key in the state. The checkbox can also display a label, and it supports action execution upon interaction.

Component Name: checkbox

JSON key: "component": "checkbox"

Parameters

Parameter KeyJSON Value TypeFlutter TypeDescriptionDefault ValueNullableRequires Build
valueStringboolThe key representing the checkbox's state in the page's state. When the checkbox is toggled, the value associated with this key is updated to reflect the new state (true/false). This key should be formatted as ${key} (e.g., ${active}).NoneNoNo
labelStringStringThe text label displayed next to the checkbox. If not provided, the checkbox will be rendered without a label.NoneYesNo
actiondynamicdynamicA JSON action that is executed when the checkbox is clicked. This allows for additional behaviors or state updates beyond the checkbox's inherent functionality.NoneYesNo
colorStringColorThe color of the checkbox when active. Accepts Flutter color names or hex codes.Theme default colorYesNo
widthnum (Number)doubleThe width of the checkbox component.None (Intrinsic width)YesNo
heightnum (Number)doubleThe height of the checkbox component.None (Intrinsic height)YesNo
paddingList<num>EdgeInsetsPadding to be applied around the checkbox. Expects a list of numbers representing padding values (e.g., [left, top, right, bottom]).NoneYesNo
marginList<num>EdgeInsetsMargin to be applied around the checkbox. Expects a list of numbers representing margin values (e.g., [left, top, right, bottom]).NoneYesNo
alignmentStringAlignmentGeometryHow the checkbox should be aligned within its allocated space. Accepts alignment keywords like 'topLeft', 'center', 'bottomRight', etc. Refer to Flutter's Alignment documentation.Defaults to topLeftYesNo

Note:

  • Action-Driven Behavior: The MiCheckbox component is designed to trigger actions when interacted with. The action parameter allows for executing additional logic beyond the checkbox's state change. When the checkbox is clicked, it invokes the action defined in the action parameter, which can be a JSON object specifying the action type and parameters.
  • State Management Integration: The value parameter represents a key in the application's state management system. When the checkbox is toggled, the value associated with this key is updated to reflect the new checkbox state (true or false).
  • Inherited Parameters: The color, alignment, width, height, padding, and margin parameters are inherited from MiStatelessWidget.
  • Styling and Layout Flexibility: The MiCheckbox component allows for customization of its appearance and layout through inherited parameters.

Example JSON Configurations

Example 1: Basic Checkbox without Label

{
"component": "checkbox",
"value": "${active}",
"action": {
"actionType": "customAction"
}
}

Explanation of Example 1:

  • component: "checkbox" - Identifies this configuration as being for a MiCheckbox component.
  • value: "${active}" - Sets the checkbox's state to be linked with the key ${active}. When toggled, the state of ${active} will be updated to reflect the checkbox's new value (true or false).
  • action - Defines the action to be executed when the checkbox is clicked.

Example 2: Checkbox with Label

{
"component": "checkbox",
"value": "${notificationsEnabled}",
"label": "Enable Notifications",
"action": {
"actionType": "customAction"
}
}

Explanation of Example 2:

  • component: "checkbox" - Identifies this configuration as being for a MiCheckbox component.
  • value: "${notificationsEnabled}" - Links the checkbox's state to the key ${notificationsEnabled}. The checkbox will reflect the current state of this key, and toggling it will update the key accordingly.
  • label: "Enable Notifications" - Provides a label for the checkbox, enhancing user understanding of its purpose.
  • action - Specifies the action to be executed when the checkbox is clicked.