connect static method

Future<EventSource> connect(
  1. dynamic url, {
  2. Client? client,
  3. String? lastEventId,
  4. Map? headers,
  5. String? body,
  6. String? method,
  7. bool? openOnlyOnFirstListener,
  8. StreamController<EventSourceReadyState>? readyStateController,
  9. bool? closeOnLastListener,
})

Create a new EventSource by connecting to the specified url. If you want to be able to listen to the state changes you need to provide your own readyStateController as broadcast controllers do not store state.

Implementation

static Future<EventSource> connect(url,
    {http.Client? client,
    String? lastEventId,
    Map? headers,
    String? body,
    String? method,
    bool? openOnlyOnFirstListener,
    StreamController<EventSourceReadyState>? readyStateController,
    bool? closeOnLastListener}) async {
  // parameter initialization
  url = url is Uri ? url : Uri.parse(url);
  client = client ?? new http.Client();
  lastEventId = lastEventId ?? "";
  body = body ?? "";
  method = method ?? "GET";
  EventSource es = new EventSource._internal(url, client, lastEventId,
      headers, body, method, openOnlyOnFirstListener, closeOnLastListener,
      readyStateController);
  if (!es._openOnlyOnFirstListener) {
    await es._start();
  }
  return es;
}