languagetool_textfield icon indicating copy to clipboard operation
languagetool_textfield copied to clipboard

onTextChange call

Open zthrive opened this issue 10 months ago • 2 comments

It appears that onTextChange call does not take in account corrected spelling. If I use the controller, everything works as expected. However, this makes my code more complex and difficult to maintain.

zthrive avatar Mar 09 '25 04:03 zthrive

Yes I confirm that when we apply a correction through the pop-up the callback is not called and there's no other events that could notify us. Did you find a workaround @zthrive?

ZephyrRaine avatar Jun 11 '25 14:06 ZephyrRaine

While this issue is being fixed, here's how I'm handling the focus behavior in my implementation... Not perfect but it does the trick for my usage (since i don't need the updated values until i'm clicking out of the textfields)

// Initialize focus nodes
late final FocusNode _commentsFocusNode;
late final FocusNode _conductFocusNode;

@override
void initState() {
  super.initState();
  _commentsFocusNode = FocusNode();
  _commentsFocusNode.addListener(() {
    if (!_commentsFocusNode.hasFocus) {
      widget.onCommentsChanged?.call(_commentsController.text);
    }
  });

  _conductFocusNode = FocusNode();
  _conductFocusNode.addListener(() {
    if (!_conductFocusNode.hasFocus) {
      widget.onConductChanged?.call(_conductController.text);
    }
  });
}

@override
void dispose() {
  _commentsFocusNode.dispose();
  _conductFocusNode.dispose();
  super.dispose();
}

@override
Widget build(BuildContext context) {
  return AppCard(
    child: Column(
      children: [
        // ... other widgets ...
        AppLangTextField(
          controller: _commentsController,
          focusNode: _commentsFocusNode,
          // ... other properties ...
        ),
        // ... other widgets ...
        AppLangTextField(
          controller: _conductController,
          focusNode: _conductFocusNode,
          // ... other properties ...
        ),
        // ... other widgets ...
      ],
    ),
  );
}

ZephyrRaine avatar Jun 11 '25 14:06 ZephyrRaine