DiscoverModule/lib/connectivity.dart

34 lines
985 B
Dart

import 'dart:async';
import 'dart:io';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dio/dio.dart';
class NetworkConnectivity {
// Future<bool> isInternetAvailable() async {
// var connectivityResult = await (Connectivity().checkConnectivity());
// return connectivityResult != ConnectivityResult.none;
// }
Future<bool> isInternetAvailable() async {
var connectivityResult = await Connectivity().checkConnectivity();
if (connectivityResult == ConnectivityResult.none) {
return false;
} else {
try {
// final result = await InternetAddress.lookup('google.com');
// return true;
final result = await Dio().get('www.google.com');
if (result.statusCode == 200) {
// if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
return true;
//}
}
return false;
} on SocketException catch (_) {
return false;
}
}
}
}