PerfectTextController constructor

PerfectTextController({
  1. TextEditingController? textEditingController,
  2. FocusNode? focusNode,
  3. bool selectAllOnFocus = true,
  4. bool readyOnly = false,
  5. void onTextChange(
    1. String value
    )?,
  6. void onFocusChange(
    1. bool value
    )?,
})

Implementation

PerfectTextController({
  TextEditingController? textEditingController,
  FocusNode? focusNode,
  bool selectAllOnFocus = true,
  bool readyOnly = false,
  this.onTextChange,
  this.onFocusChange,
})  : textController = textEditingController ?? TextEditingController(),
      focusNode = focusNode ??
          (readyOnly
              ? FocusNode(
                  skipTraversal: true,
                  canRequestFocus: false,
                  descendantsAreFocusable: false,
                  descendantsAreTraversable: false,
                )
              : FocusNode()) {
  textController.addListener(() {
    if (rxText.value != textController.text) {
      rxText.value = textController.text;
    }
    if (onTextChange != null) {
      onTextChange?.call(text);
    }
  });

  this.focusNode.addListener(() {
    PerfectTextController.focused =
        this.focusNode.hasPrimaryFocus ? this : null;

    if (selectAllOnFocus) {
      onFocusChange?.call(this.focusNode.hasPrimaryFocus);
      if (this.focusNode.hasPrimaryFocus) {
        selectAll();
      }
    }
  });
}