initialize method
Initializes the plugin with an optional TestController
. If the
TestController
is not set then this acts as nothing more than a wrapper
to
Implementation
Future<void> initialize({
Stream<bool>? connectedStream,
TestController? testController,
}) async {
if (_initialized != true) {
_testController = testController;
_initialized = true;
if (connectedStream != null) {
_connectivitySubscription = connectedStream.listen(
(connected) => _updateData(connected),
);
} else {
_connectivity =
Connectivity(); // Try to set up the listener, but don't blow up the app just because the
// listener can't be registered (ie: we're on an unsupported platform).
runZonedGuarded(() {
_connectivitySubscription =
_connectivity?.onConnectivityChanged.listen(
(ConnectivityResult result) => _updateData(_getConnected(result)),
);
}, (_, __) {
// no-op
});
}
await refresh();
}
}