createButton method

Widget createButton(
  1. BuildContext context
)
inherited

Implementation

Widget createButton(BuildContext context) {
  Widget child = TextButton(
    style: ButtonStyle(
      backgroundColor:
          WidgetStateProperty.resolveWith<Color?>((states) => _buttonElement.renderStyle.backgroundColor?.value),
    ),
    onPressed: () {
      var box = context.findRenderObject() as RenderBox;
      Offset globalOffset = box.globalToLocal(Offset(Offset.zero.dx, Offset.zero.dy));
      double clientX = globalOffset.dx;
      double clientY = globalOffset.dy;
      Event event = MouseEvent(EVENT_CLICK,
          clientX: clientX, clientY: clientY, view: _buttonElement.ownerDocument.defaultView);
      _buttonElement.dispatchEvent(event);
    },
    child: Text(_buttonElement.value, style: _buttonStyle),
  );

  // Apply accessibility semantics if label present (aria-label/aria-labelledby)
  final String? semanticsLabel = WebFAccessibility.computeAccessibleName(_buttonElement);
  final String? role = _buttonElement.getAttribute('role')?.toLowerCase();
  final String? ariaSel = _buttonElement.getAttribute('aria-selected')?.toLowerCase();
  final bool selected = role == 'tab' && ariaSel == 'true';
  final bool disabled = _buttonElement.getAttribute('aria-disabled')?.toLowerCase() == 'true';

  // Always provide semantics for buttons to expose selected/mutual exclusivity for tabs.
  child = Semantics(
    label: (semanticsLabel != null && semanticsLabel.isNotEmpty) ? semanticsLabel : null,
    button: true,
    selected: selected,
    inMutuallyExclusiveGroup: role == 'tab',
    enabled: !disabled,
    textDirection: _buttonElement.renderStyle.direction,
    child: child,
  );

  return Directionality(textDirection: TextDirection.ltr, child: child);
}