-
Notifications
You must be signed in to change notification settings - Fork 849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClipboardMonitor causes background lag when enabling clipboard buttons #2421
Comments
It is possible there is a better implementation of Clipboard Monitor. I will try to take a look myself and tweak some stuff to see if it is any better. Right now it re-instantiates the ClipboardService every second, which could be an issue. class ClipboardMonitor {
bool _canPaste = false;
bool get canPaste => _canPaste;
Timer? _timer;
void monitorClipboard(bool add, void Function() listener) {
if (kIsWeb) return;
if (add) {
_timer = Timer.periodic(
const Duration(seconds: 1), (timer) => _update(listener));
} else {
_timer?.cancel();
}
}
Future<void> _update(void Function() listener) async {
final clipboardService = ClipboardServiceProvider.instance;
if (await clipboardService.hasClipboardContent) {
_canPaste = true;
listener();
}
}
} |
Did you encounter the issue with older versions in case you used them?
To clarify, the I will disable those buttons as a breaking change in v11 since they were already not enabled and introduced as unexpected change in a minor release. Related lines. I'm thinking about removing them since supporting them is not a priority, and it's better to support less well-done and maintained features. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
Just a very convenient way to use some actions (especially paste). I have no problem implementing them on my own, but I'll give it a try to fix buttons / clipboard monitor, so those actions are available for everyone using the plugin from toolbar as well.
After a second thought, I do use them for pasting images. I'll give it a proper test and come back to it later on |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
One possible solution is to listen to the system clipboard changes, which involves platform-specific code and might not be available on some platforms or has some restrictions.
I was considering replacing it with platform code in
How would they solve it? It's not possible without platform code AFAIK, and I think users prefer something that's already implemented without much configuration. For now, we should notify users about this issue before they enable those buttons. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
BTW, the current solution needs improvement. The
The issue is how we can listen to clipboard state changes, and the current solution achieves that by running platform code every 1 second from the Dart side, which is not efficient.
Assuming they have greater control, I will check to see if it's possible using platform code. |
I think it comes to the discussion if the "canPaste" flag is even needed for the in-built "paste" button. For my use case I would just completely remove the canPaste flag and make it always active, and handle the exceptions/empty clipboard when I actually interact with the button |
Is there an existing issue for this?
Flutter Quill version
flutter_quill: ^11.0.0-dev.17 & flutter_quill_extensions: ^11.0.0-dev.7
Steps to reproduce
QuillSimpleToolbar
and passQuillSimpleToolbarConfig
withshowClipboardCut
,showClipboardCopy
, orshowClipboardPaste
set to trueSource code for reference:
QuillToolbarClipboardButton
was added to the Widget tree, it starts affecting the app performance & memory on the background, even if you are not actively copying or pasting with clipboard at the moment.Expected results
Expected Clipboard to not be as heavy for the application and to not cause performance issues.
Actual results
ClipboardService causes background lag when used.
The text was updated successfully, but these errors were encountered: