You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemm-flutter-app/lib/services/network_service.dart

26 lines
650 B
Dart

import 'dart:io';
abstract class INetworkService {
Future<bool> isHostAvailable(String endpoint);
}
class NetworkService implements INetworkService{
@override
Future<bool> isHostAvailable(String endpoint) async {
try {
final result = await InternetAddress.lookup(endpoint.substring(endpoint.indexOf('//')+2).substring(0,endpoint.substring(endpoint.indexOf('//')+2).indexOf('/')));
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
return true;
} else{
return false;
}
} on SocketException catch (_) {
return false;
}
}
}
class NetworkException implements Exception {
}