Flutter IsolateNameServer.注册端口后,lookupPortByName返回null



我正在尝试注册一个流事件侦听器的端口,并面临一个错误,即在端口注册后,我无法查找相同的端口,因为它每次都返回null我正在寻找它。

if (IsolateNameServer.lookupPortByName("_notficationListener_") == null) {
print('going to fresh port');
IsolateNameServer.registerPortWithName(
receivePort.sendPort, "_notificationListener_");
NotificationsListener.initialize(callbackHandle: _callback);
receivePort.listen((var message) => {
print(
"Checking whether it is passing or not ======================"),
onData(message)
});
bool? isRunning = await NotificationsListener.isRunning;
if (kDebugMode) {
print("""Service is ${isRunning == false ? "not" : ""} running""");
}
started = isRunning!;
} else {
IsolateNameServer.removePortNameMapping("_notficationListener_");
IsolateNameServer.registerPortWithName(
receivePort.sendPort, "_notificationListener_");
NotificationsListener.initialize(callbackHandle: _callback);
receivePort.listen((var message) => {
print(
"Checking whether it is passing or not ======================"),
onData(message)
});
bool? isRunning = await NotificationsListener.isRunning;
if (kDebugMode) {
print("""Service is ${isRunning == false ? "not" : ""} running""");
}
started = isRunning!;
}
if (kDebugMode) {
print(
"port is present ${IsolateNameServer.lookupPortByName("_notficationListener_")}");
}

这是我正在工作的代码。任何帮助都将不胜感激。软件包用户Flutter Isolate

IsolateNameServer.registerPortWithName(receivePort。sendPort,">notificationListener");是有一些错误与尾__和__之前的名称,我删除了它,它的工作。

相关内容

  • 没有找到相关文章

最新更新