buildToggleable method Null safety

Widget buildToggleable(
  1. {FocusNode? focusNode,
  2. bool autofocus = false,
  3. required MaterialStateProperty<MouseCursor> mouseCursor,
  4. required Size size,
  5. 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,
  bool autofocus = false,
  required MaterialStateProperty<MouseCursor> mouseCursor,
  required Size size,
  required CustomPainter painter,
}) {
  return FocusableActionDetector(
    actions: _actionMap,
    focusNode: focusNode,
    autofocus: autofocus,
    enabled: isInteractive,
    onShowFocusHighlight: _handleFocusHighlightChanged,
    onShowHoverHighlight: _handleHoverChanged,
    mouseCursor: mouseCursor.resolve(states),
    child: GestureDetector(
      excludeFromSemantics: !isInteractive,
      onTapDown: _handleTapDown,
      onTap: _handleTap,
      onTapUp: _handleTapEnd,
      onTapCancel: _handleTapEnd,
      child: Semantics(
        enabled: isInteractive,
        child: CustomPaint(
          size: size,
          painter: painter,
        ),
      ),
    ),
  );
}