InternetConnection.createInstance constructor
InternetConnection.createInstance({
- Duration? checkInterval,
- List<
InternetCheckOption> ? customCheckOptions, - bool useDefaultOptions = true,
- bool enableStrictCheck = false,
- 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
useDefaultOptionsistrue(default), the default Uris will be used along with anycustomCheckOptionsprovided. -
If
useDefaultOptionsisfalse, you must provide a non-emptycustomCheckOptionslist.
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;
}