22 lines
576 B
Dart
22 lines
576 B
Dart
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<Map<String, dynamic>?> on(String method) {
|
|
if (service != null) {
|
|
return service!.on(method);
|
|
}
|
|
|
|
return receivePort!
|
|
.where((event) => event['method'] == method)
|
|
.map((event) => (event as Map?)?.cast<String, dynamic>());
|
|
}
|
|
}
|