start method
- {BuildContext? context,
- Widget? fallBackScreen,
- ConnectivityDisplayType? connectivityDisplayType}
Starts the service.
context is required when using the default handler.
fallBackScreen is required when using the default handler.
fallBackScreen is the screen that will be pushed when there is no
internet connection.
fallBackScreen is the screen that will be popped when there is an
internet connection.
fallBackScreen is only used when using the default handler.
noInternetEnum is only used when using the default handler.
Implementation
void start({
BuildContext? context,
Widget? fallBackScreen,
ConnectivityDisplayType? connectivityDisplayType,
}) {
_timer ??= Timer.periodic(_config.duration, (t) async {
_previousConnection = _connection;
if (kIsWeb && _config.webUrl == null) {
throw Exception(
'To make flutter_connectivity work for web please specify a webUrl'
' in the config. Make sure, CORS is not an issue',
);
}
_connection = await _config.checker.checkConnection(_config);
if (_config.handler is DefaultFlutterHandler) {
if (context == null) {
throw Exception('Context is required when using the default handler');
}
(_config.handler as DefaultFlutterHandler).init(
context,
fallBackScreen ??
NoInternetScreen(
connectivityDisplayType:
connectivityDisplayType ?? ConnectivityDisplayType.screen,
),
connectivityDisplayType ?? ConnectivityDisplayType.screen,
);
}
if (_previousConnection && !_connection) {
_config.handler.onConnectionLost();
} else if (!_previousConnection && _connection) {
_config.handler.onConnectionRestored();
}
});
}