initConnectivity method

Future<void> initConnectivity()

initialize connectivity checking Platform messages are asynchronous, so we initialize in an async method.

Implementation

Future<void> initConnectivity() async {
  try {
    await _connectivity.checkConnectivity();
  } on PlatformException catch (e) {
    print(e.toString());
  }

  // If the widget was removed from the tree while the asynchronous platform
  // message was in flight, we want to discard the reply rather than calling
  // setState to update our non-existent appearance.
  if (!mounted) {
    return;
  }

  await _updateConnectionStatus().then((bool isConnected) => setState(() {
    isOnline = isConnected;
  }));
}