parseInlineSpan function

InlineSpan? parseInlineSpan(
  1. ThemeData theme,
  2. ControlTreeViewModel spanViewModel,
  3. bool parentDisabled,
  4. void sendControlEvent(
    1. String,
    2. String,
    3. String
    )?,
)

Implementation

InlineSpan? parseInlineSpan(
    ThemeData theme,
    ControlTreeViewModel spanViewModel,
    bool parentDisabled,
    void Function(String, String, String)? sendControlEvent) {
  if (spanViewModel.control.type == "textspan") {
    bool disabled = spanViewModel.control.isDisabled || parentDisabled;
    var onClick = spanViewModel.control.attrBool("onClick", false)!;
    String url = spanViewModel.control.attrString("url", "")!;
    String? urlTarget = spanViewModel.control.attrString("urlTarget");
    return TextSpan(
      text: spanViewModel.control.attrString("text"),
      style: parseTextStyle(theme, spanViewModel.control, "style"),
      spellOut: spanViewModel.control.attrBool("spellOut"),
      semanticsLabel: spanViewModel.control.attrString("semanticsLabel"),
      children: parseTextSpans(
          theme, spanViewModel, parentDisabled, sendControlEvent),
      mouseCursor: onClick && !disabled && sendControlEvent != null
          ? SystemMouseCursors.click
          : null,
      recognizer:
          (onClick || url != "") && !disabled && sendControlEvent != null
              ? (TapGestureRecognizer()
                ..onTap = () {
                  debugPrint("TextSpan ${spanViewModel.control.id} clicked!");
                  if (url != "") {
                    openWebBrowser(url, webWindowName: urlTarget);
                  }
                  if (onClick) {
                    sendControlEvent(spanViewModel.control.id, "click", "");
                  }
                })
              : null,
      onEnter: spanViewModel.control.attrBool("onEnter", false)! &&
              !disabled &&
              sendControlEvent != null
          ? (event) {
              debugPrint("TextSpan ${spanViewModel.control.id} entered!");
              sendControlEvent(spanViewModel.control.id, "enter", "");
            }
          : null,
      onExit: spanViewModel.control.attrBool("onExit", false)! &&
              !disabled &&
              sendControlEvent != null
          ? (event) {
              debugPrint("TextSpan ${spanViewModel.control.id} exited!");
              sendControlEvent(spanViewModel.control.id, "exit", "");
            }
          : null,
    );
  }
  return null;
}