lookupById method
Returns a Document object containing the app's details.
Implementation
Future<Document?> lookupById(String id,
{String? country = 'US',
String? language = 'en'}) async {
// Ensure the ID is not empty.
assert(id.isNotEmpty);
if (id.isEmpty) return null;
// Generate the URL for the API request.
final url = lookupURLById(id,
country: country, language: language)!;
// Log the final URL for debugging purposes.
if (kDebugMode) {
print('Version Sentry: Final url: $url');
}
try {
// Send a GET request to the API.
final response = await client!.get(Uri.parse(url));
// Check if the response was successful.
if (response.statusCode < 200 || response.statusCode >= 300) {
// Log an error message if the response was not successful.
if (kDebugMode) {
print('Version Sentry: Can\'t App || App id: $id');
}
return null;
}
// Decode the response body into a [Document] object.
final decodedResults = _decodeResults(response.body);
return decodedResults;
} on Exception catch (e) {
// Log an error message if an exception occurs.
if (kDebugMode) {
print('Version Sentry: API Error: $e');
}
return null;
}
}