isInternetConnected method

Future<bool> isInternetConnected()

Implementation

Future<bool> isInternetConnected() async {
  //ping -c 4 google.com
  try {
    final res = await Process.run('ping', ['-c', '4', 'google.com']);
    if (res.stderr.toString().isNotEmpty) {
      return false;
    }
    if (res.stdout.toString().isNotEmpty) {
      return true;
    }

    // print('succ: ${res.stdout}');
    // print('error: ${res.stderr}');
  } catch (e) {
    ThanPkg.showDebugLog(e.toString(), tag: 'LinuxApp:isInternetConnected');
  }

  return false;
}