controlWebServer 静态方法
通过服务协议访问的 Web 服务器进行控制。使用 enable
作为启用或禁用处理请求的 Web 服务器的切换。如果提供并且为 true 的 silenceOutput
,则服务器不会将信息输出到控制台。
实现
static Future<ServiceProtocolInfo> controlWebServer(
{bool enable = false, bool? silenceOutput}) async {
// TODO: When NNBD is complete, delete the following line.
ArgumentError.checkNotNull(enable, 'enable');
// Port to receive response from service isolate.
final RawReceivePort receivePort =
new RawReceivePort(null, 'Service.controlWebServer');
final Completer<String?> completer = new Completer<String?>();
receivePort.handler = (String? uriString) => completer.complete(uriString);
// Request the information from the service isolate.
_webServerControl(receivePort.sendPort, enable, silenceOutput);
// Await the response from the service isolate.
String? uriString = await completer.future;
Uri? uri = uriString == null ? null : Uri.parse(uriString);
// Close the port.
receivePort.close();
return new ServiceProtocolInfo(uri);
}