35 lines
896 B
Dart
35 lines
896 B
Dart
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();
|
|
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;
|
|
//}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
} on SocketException catch (_) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|