Replies: 6 comments 5 replies
-
Can you share the core part of your code that does the selection? |
Beta Was this translation helpful? Give feedback.
-
We appreciate you taking a look. I myself am not much of a programmer.. but I have seen some of this code for some dictionary and sentence reference collection I did for flash cards. We only change the html to "highlight" |
Beta Was this translation helpful? Give feedback.
-
The question is.. this is a test How do I select the word "test" as if the user selected the word, provided the widget is inside a SelectionArea |
Beta Was this translation helpful? Give feedback.
-
The context menu items can be found here |
Beta Was this translation helpful? Give feedback.
-
It turned out you can dispatch a final key = GlobalKey();
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SelectionArea(
onSelectionChanged: (value) {
print('onSelectionChanged: ${value?.plainText}');
},
child: Builder(
builder: (context) {
final registrar = SelectionContainer.maybeOf(context);
return GestureDetector(
onTapUp: (details) {
if (registrar is! MultiSelectableSelectionContainerDelegate) {
// registrar should be this class if a `SelectionArea` is in the widget tree
return;
}
registrar.dispatchSelectionEvent(SelectWordSelectionEvent(globalPosition: details.globalPosition));
final tapped = registrar.getSelectedContent();
// selecting word this way won't trigger the `onSelectionChanged` callback
print('onTapUp: ${tapped?.plainText}');
},
child: HtmlWidget(html, key: key),
);
},
),
),
);
}
} |
Beta Was this translation helpful? Give feedback.
-
So the fix works in Linux.. but not Windows. Sorry to report early that it was fixed. The other programmer might help though |
Beta Was this translation helpful? Give feedback.
-
The recent upgrade from Flutter 3.13.x fixed a right click issue for someone but broke it for us.
Normally we have a click-to-dictionary and we mark the word as highlighted, but it is just html dom stuff.
Recently we switched to the proper way to do right click because some things were headed for depreciated and not supported. Everything worked in flutter 3.10.6 but 3.13.x stopped working.
What happened is that the system or framework was automatically selecting the nearest word (which happened to have highlighted elements on it). Then the right click menu would detect a word was selected. We got lucky and used this for a release or two. However, it was not really "selected" and just visually selected.
You can read this issue here which explains the issue a little bit more
flutter/flutter#117561
So we need a way to programatically select a word when the user clicks. Right now we just change the color and make it appear that it is "selected".
The question here is.. is there a way to actually select something with a mere click of the mouse or right click.
The problem does not exist in android because to get a context menu, one needs to long press. Long pressing defaults to selected the nearest word.
Beta Was this translation helpful? Give feedback.
All reactions