CheckTag class
A tag that behaves like a checkbox.
Sometimes a form needs a checkbox, but the button-style checkbox does not
fit the design. A CheckTag fills that gap: it is a Tag that toggles
between a checked and an unchecked state when tapped.
When checked it looks like a normal Tag of the given type and theme. When unchecked it flattens to a light grey fill with grey text and no visible border, so the eye is drawn to the selected items.
The widget works in two modes:
- Uncontrolled – leave checked
null. The tag keeps its own state, starting from initialChecked, and reports every change through the callbacks. - Controlled – pass checked. The tag renders exactly that value and never changes it by itself; update your state in onChanged and rebuild.
CheckTag(
'Flutter',
checked: _selected,
onChanged: (value) => setState(() => _selected = value),
)
Three callbacks are available. onChanged receives the new value on every toggle, while onChecked and onUnchecked fire only for the matching transition, which reads better when the two directions do different work.
The tag is focusable; Space and Enter toggle it.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- CheckTag
Constructors
-
CheckTag(String text, {Key? key, bool? checked, bool initialChecked = false, ValueChanged<
bool> ? onChanged, VoidCallback? onChecked, VoidCallback? onUnchecked, bool disabled = false, SemanticEnum type = SemanticEnum.primary, Color? color, TagThemeEnum theme = TagThemeEnum.light, SizeEnum size = SizeEnum.defaultSize, double? radius, double? height, double? width, bool shrink = true, bool showCheckIcon = false, bool autofocus = false, FocusNode? focusNode}) -
const
Properties
- autofocus → bool
-
Whether the tag requests focus when first built.
final
- checked → bool?
-
The current value in controlled mode.
final
- color → Color?
-
A custom accent colour used while checked. Takes precedence over type.
final
- disabled → bool
-
Whether the tag ignores input. A disabled tag is drawn dimmed.
final
- focusNode → FocusNode?
-
An optional focus node to control keyboard focus from outside.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double?
-
An explicit height, overriding size.
final
- initialChecked → bool
-
The starting value in uncontrolled mode. Ignored when checked is set.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onChanged
→ ValueChanged<
bool> ? -
Called with the new value every time the tag is toggled.
final
- onChecked → VoidCallback?
-
Called when the tag goes from unchecked to checked.
final
- onUnchecked → VoidCallback?
-
Called when the tag goes from checked to unchecked.
final
- radius → double?
-
The corner radius. Falls back to the theme's base radius.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showCheckIcon → bool
-
Whether to draw a check mark before the label while checked.
final
- shrink → bool
-
Whether the tag hugs its content. Set to
falseto fill the parent.final - size → SizeEnum
-
The size of the tag.
final
- text → String
-
The label of the tag.
final
- theme → TagThemeEnum
-
The appearance of the checked state:
plain,lightordark.final - type → SemanticEnum
-
The semantic colour used while checked.
final
- width → double?
-
An explicit width. When
nullthe tag is as wide as its content.final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< CheckTag> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited