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

45 lines
1.3 KiB
Dart
Raw Normal View History

2024-10-08 12:01:59 +00:00
import 'dart:async';
import 'dart:io';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.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 {
if (!kIsWeb) {
final result = await InternetAddress.lookup('google.com');
return true;
} else {
final result = await Dio().get('www.google.com');
if (result.statusCode == 200) {
// if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
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;
}
}
}
}