DiscoverModule/lib/ui_screen/interactionform/NewtworkConnectivity.dart

28 lines
809 B
Dart
Raw Normal View History

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';
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 {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
return true;
}
return false;
} on SocketException catch (_) {
return false;
}
}
2024-05-20 10:29:02 +00:00
}
}