Open ugirishm opened 7 months ago
Hi @ugirishm you need to use shareData method to share data from variables to overlay and to get data on overlay you need to use overlayListener so that you can listen to the data and get it and update data on the overlay. I hope you'll find this helpfull.
share data example:
if (!(await FlutterOverlayWindow.isPermissionGranted())) return; if (await FlutterOverlayWindow.isActive()) return;
await FlutterOverlayWindow.showOverlay( enableDrag: true, flag: OverlayFlag.defaultFlag, visibility: NotificationVisibility.visibilityPublic, height: 300, width: WindowSize.matchParent, ); await Future.delayed(const Duration(milliseconds: 200)); await FlutterOverlayWindow.shareData('$order,$pNumber');
Listen Data Example: String firstTitle = ''; String secTitle = '';
@override void initState() { super.initState(); FlutterOverlayWindow.overlayListener.listen((event) { log("$event"); setState(() { // isGold = !isGold; print('true call event $event'); if (event.toString().contains(',')) { String data = event.toString();
try {
print('try to set data');
firstTitle = data.split(',').first;
secTitle = data.split(',')[1];
} catch (e) {
print('exception $e');
firstTitle = '';
secTitle = '';
}
print('after all result on overlay: $firstTitle $secTitle');
}
});
});
setState(() {});
Future.delayed(const Duration(milliseconds: 400), () {
setState(() {});
});
}
@M-ImranNawaz How to do the opposite direction? Share data from the overlay. The above method doesn't work as the listen doesn't get any events. Thanks
When background service is added with flutter_background_service, able to send data using FlutterBackgroundService.invoke, but not able to receive data using FlutterBackgroundService.on.
FlutterBackgroundService.on works fine when implemented in non-overlay screens.