2024-05-20 10:29:02 +00:00
|
|
|
import 'dart:async';
|
2024-06-28 08:14:42 +00:00
|
|
|
import 'dart:io';
|
2024-05-20 10:29:02 +00:00
|
|
|
|
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
2024-07-05 08:48:29 +00:00
|
|
|
import 'package:dio/dio.dart';
|
2024-05-20 10:29:02 +00:00
|
|
|
|
|
|
|
class NetworkConnectivity {
|
2024-06-28 08:14:42 +00:00
|
|
|
// Future<bool> isInternetAvailable() async {
|
|
|
|
// var connectivityResult = await (Connectivity().checkConnectivity());
|
|
|
|
// return connectivityResult != ConnectivityResult.none;
|
|
|
|
// }
|
2024-05-20 10:29:02 +00:00
|
|
|
Future<bool> isInternetAvailable() async {
|
2024-06-28 08:14:42 +00:00
|
|
|
var connectivityResult = await Connectivity().checkConnectivity();
|
|
|
|
if (connectivityResult == ConnectivityResult.none) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
try {
|
2024-07-05 08:48:29 +00:00
|
|
|
// final result = await InternetAddress.lookup('google.com');
|
|
|
|
final result = await Dio().get('www.google.com');
|
|
|
|
|
|
|
|
if (result.statusCode == 200) {
|
|
|
|
// if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
|
2024-06-28 08:14:42 +00:00
|
|
|
return true;
|
2024-07-05 08:48:29 +00:00
|
|
|
//}
|
2024-06-28 08:14:42 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} on SocketException catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-05-20 10:29:02 +00:00
|
|
|
}
|
|
|
|
}
|