import 'dart:isolate'; import 'package:flutter_background_service/flutter_background_service.dart'; class ServiceInterface { final ReceivePort? receivePort; final ServiceInstance? service; ServiceInterface({this.receivePort, this.service}) : assert(receivePort != null || service != null); Stream?> on(String method) { if (service != null) { return service!.on(method); } return receivePort! .where((event) => event['method'] == method) .map((event) => (event as Map?)?.cast()); } }