subscription method

Future<void> subscription({
  1. UnavailableNetworkAlertBuilder? alertUnavailableNetwork,
  2. bool willPop = true,
})

订阅网络监听

Implementation

Future<void> subscription({
  /// 网络不可用 时 弹出 Overlay 禁止操作
  UnavailableNetworkAlertBuilder? alertUnavailableNetwork,

  /// [alertUnavailableNetwork]弹出时 安卓上限制实体返回按键操作
  /// [ExtendedScaffold] 中 [onWillPopOverlayClose] 必须为 true 才有效
  bool willPop = true,
}) async {
  if (_subscription != null) return;
  log('Connectivity 初始化', crossLine: false);

  /// 添加模态框
  if (alertUnavailableNetwork != null) {
    _overlayCallback ??= (_, __) => showOverlayWhenUnavailableNetwork(
        alertUnavailableNetwork,
        willPop: willPop);
    _listenerList.add(_overlayCallback!);
  }
  await checkConnectivity();
  _subscription = connectivity.onConnectivityChanged
      .listen((ConnectivityResult connectivityResult) async {
    if (_currentStatus == connectivityResult) return;
    _currentStatus = connectivityResult;
    log('Connectivity 网络状态变化 $_currentStatus', crossLine: false);
    _callListenerList();
  });
}