InternetConnection.createInstance constructor

InternetConnection.createInstance({
  1. Duration? checkInterval,
  2. List<InternetCheckOption>? customCheckOptions,
  3. bool useDefaultOptions = true,
  4. bool enableStrictCheck = false,
  5. ConnectivityCheckCallback? customConnectivityCheck,
})

Creates an instance of InternetConnection.

The checkInterval defines the interval duration between status checks.

The customCheckOptions specify the list of Uris to check for connectivity.

The useDefaultOptions flag indicates whether to use the default Uris.

  • If useDefaultOptions is true (default), the default Uris will be used along with any customCheckOptions provided.

  • If useDefaultOptions is false, you must provide a non-empty customCheckOptions list.

The customConnectivityCheck allows you to provide a custom method for checking endpoint reachability. If provided, it will be used for all connectivity checks instead of the default HTTP HEAD request implementation.

Implementation

InternetConnection.createInstance({
  Duration? checkInterval,
  List<InternetCheckOption>? customCheckOptions,
  bool useDefaultOptions = true,
  this.enableStrictCheck = false,
  this.customConnectivityCheck,
})  : _checkInterval = checkInterval ?? _defaultCheckInterval,
      assert(
        useDefaultOptions || customCheckOptions?.isNotEmpty == true,
        'You must provide a list of options if you are not using the '
        'default ones.',
      ) {
  _internetCheckOptions = [
    if (useDefaultOptions) ..._defaultCheckOptions,
    if (customCheckOptions != null) ...customCheckOptions,
  ];

  _statusController.onListen = _maybeEmitStatusUpdate;
  _statusController.onCancel = _handleStatusChangeCancel;
}