transferDataToPresentation method
Transfer data to a secondary display
Transfer data from main screen to a secondary display Consider using [arguments] for cases where a particular run-time type is expected. Consider using String when that run-time type is Map or JSONObject.
Main Screen
DisplayManager displayManager = DisplayManager();
...
static Future<void> transferData(Song song) async {
displayManager.transferDataToPresentation(<String, dynamic>{
'id': song.id,
'title': song.title,
'artist': song.artist,
});
}
Secondary display
class _SecondaryScreenState extends State<SecondaryScreen> {
@override
Widget build(BuildContext context) {
return PresentationDisplay(
callback: (argument) {
Song.fromJson(argument)
},
child: Center()
);
}
}
Class Song
class Song {
Song(this.id, this.title, this.artist);
final String id;
final String title;
final String artist;
static Song fromJson(dynamic json) {
return Song(json['id'], json['title'], json['artist']);
}
}
return Future<bool> the value to determine whether or not the data has been transferred successfully
Implementation
Future<bool?>? transferDataToPresentation(dynamic arguments) async {
return await _displayMethodChannel?.invokeMethod<bool?>(
_transferDataToPresentation, arguments);
}