setHostInfo method
Try to find the host name of this device, if not exist host name will stay null
Implementation
Future<String?> setHostInfo() async {
// For some reason when internetAddress.host get called before the reverse
// there is weired value
weirdHostName = internetAddress.host;
// In the future if mdnsInfo is null it will execute a search
// Currently the functionality is missing in dart multicast_dns package
// https://github.com/flutter/flutter/issues/96755
try {
internetAddress = await internetAddress.reverse();
return internetAddress.host;
} catch (e) {
if (e is SocketException &&
e.osError != null &&
(e.osError!.message == 'Name or service not known')) {
// Some devices does not have host name and the reverse search will just
// throw exception.
// We don't need to print this crash as it is by design.
} else {
logger.severe('Exception here: $e');
}
}
return null;
}