Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to get selected text in Dart. Since selection.toString() doesn't work as same as JavaScript (don't know whether it's a bug or not), you have to call it with JS interop.
JsObject selection = context.callMethod('getSelection', []);
String selectedText = selection.callMethod('toString', []);
print(selectedText);
JsObject rect = selection.callMethod('getRangeAt', [0]).callMethod('getBoundingClientRect', []);
print(rect['top']);
print(rect['left']);
print(rect['height']);
print(rect['width']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.