jsSetValue method

void jsSetValue(
  1. String? value,
  2. int pos
)

Implementation

void jsSetValue(String? value, int pos) {
  if (value == null) {
    _jsSetValue = value ?? '';
    controller.text = value;
  } else {
    _jsSetValue = value;
    var offset = (pos < 0 || pos >= value.length) ? value.length : pos;
    controller.value = TextEditingValue(
      text: _jsSetValue,
      selection: TextSelection.fromPosition(
        TextPosition(
          offset: offset,
          affinity: TextAffinity.downstream,
        ),
      ),
    );
    // 这里设置时候也要通知到前端
    var paramsMap = VoltronMap();
    paramsMap.push("text", value);
    context.renderBridgeManager.sendComponentEvent(
      rootId,
      id,
      TextInputController.kEventOnChangeText,
      paramsMap,
    );
  }
}