subscription method
订阅网络监听
Implementation
Future<void> subscription({
/// 网络不可用 时 弹出 Overlay 禁止操作
UnavailableNetworkAlertBuilder? alertUnavailableNetwork,
}) async {
if (_subscription != null) return;
'Connectivity 初始化'.log(crossLine: false);
/// 添加模态框
if (alertUnavailableNetwork != null) {
_overlayCallback ??=
(_, __) => showOverlayWhenUnavailableNetwork(alertUnavailableNetwork);
_listenerList.add(_overlayCallback!);
}
await checkConnectivity();
_subscription = connectivity.onConnectivityChanged
.listen((ConnectivityResult connectivityResult) async {
if (_currentStatus == connectivityResult) return;
_currentStatus = connectivityResult;
'Connectivity 网络状态变化 $_currentStatus'.log(crossLine: false);
_callListenerList();
});
}