Untitled

 avatar
faisalsalameh
dart
a year ago
662 B
1
Indexable
Never
Future<bool> onInit() async {
    final ConnectivityResult connectivityResult =
        await (Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.wifi ||
        connectivityResult == ConnectivityResult.mobile) {
      _connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
      return true;
    }
    return false;
  }

  void _updateConnectionStatus(ConnectivityResult connectivityResult) async {
    connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult != ConnectivityResult.wifi &&
        connectivityResult != ConnectivityResult.mobile) {
      // type here
    }
  }