buildToggleable method

Widget buildToggleable(
  1. {FocusNode? focusNode,
  2. ValueChanged<bool>? onFocusChange,
  3. bool autofocus = false,
  4. required MaterialStateProperty<MouseCursor> mouseCursor,
  5. required Size size,
  6. required CustomPainter painter}
)

Typically wraps a painter that draws the actual visuals of the Toggleable with logic to toggle it.

Consider providing a subclass of ToggleablePainter as a painter, which implements logic to draw a radial ink reaction for this control. The painter is usually configured with the reaction, position, reactionHoverFade, and reactionFocusFade animation provided by this mixin. It is expected to draw the visuals of the Toggleable based on the current value of these animations. The animations are triggered by this mixin to transition the Toggleable from one state to another.

This method must be called from the build method of the State class that uses this mixin. The returned Widget must be returned from the build method - potentially after wrapping it in other widgets.

Implementation

Widget buildToggleable({
  FocusNode? focusNode,
  ValueChanged<bool>? onFocusChange,
  bool autofocus = false,
  required MaterialStateProperty<MouseCursor> mouseCursor,
  required Size size,
  required CustomPainter painter,
}) {
  return FocusableActionDetector(
    actions: _actionMap,
    focusNode: focusNode,
    autofocus: autofocus,
    onFocusChange: onFocusChange,
    enabled: isInteractive,
    onShowFocusHighlight: _handleFocusHighlightChanged,
    onShowHoverHighlight: _handleHoverChanged,
    mouseCursor: mouseCursor.resolve(states),
    child: GestureDetector(
      excludeFromSemantics: !isInteractive,
      onTapDown: isInteractive ? _handleTapDown : null,
      onTap: isInteractive ? _handleTap : null,
      onTapUp: isInteractive ? _handleTapEnd : null,
      onTapCancel: isInteractive ? _handleTapEnd : null,
      child: Semantics(
        enabled: isInteractive,
        child: CustomPaint(
          size: size,
          painter: painter,
        ),
      ),
    ),
  );
}