I\'m looking for a way to monitor the Clipboard in Flutter, all I could find relating to clipboard interaction on Flutter was: Clipboard class,
does anybody know ho
It might be a little late but still. There is no need for a plugin or library, the solution could be very trivial. Here a basic example of how you can monitor ClipBoard content:
#creating a listening Stream:
final clipboardContentStream = StreamController.broadcast();
#creating a timer for updates:
Timer clipboardTriggerTime;
clipboardTriggerTime = Timer.periodic(
# you can specify any duration you want, roughly every 20 read from the system
const Duration(seconds: 5),
(timer) {
Clipboard.getData('text/plain').then((clipboarContent) {
print('Clipboard content ${clipboarContent.text}');
# post to a Stream you're subscribed to
clipboardContentStream.add(clipboarContent.text);
});
},
);
# subscribe your view with
Stream get clipboardText => clipboardController.stream
# and don't forget to clean up on your widget
@override
void dispose() {
clipboardContentStream.close();
clipboardTriggerTime.cancel();
}