DiscoverModule/lib/contacts_module/ui_screen/interactionform/NewtworkConnectivity.dart

35 lines
896 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';
2024-07-05 08:48:29 +00:00
import 'package:dio/dio.dart';
2024-07-08 04:58:57 +00:00
import 'package:flutter/foundation.dart';
2024-05-20 10:29:02 +00:00
class NetworkConnectivity {
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-08 04:58:57 +00:00
if (!kIsWeb) {
final result = await InternetAddress.lookup('google.com');
2024-06-28 08:14:42 +00:00
return true;
2024-07-08 04:58:57 +00:00
} else {
final result = await Dio().get('www.google.com');
if (result.statusCode == 200) {
// if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
return true;
//}
}
2024-06-28 08:14:42 +00:00
}
2024-07-08 04:58:57 +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
}
}