fetchStringFromUrl function

Future<String> fetchStringFromUrl(
  1. String url
)

Implementation

Future<String> fetchStringFromUrl(String url) async {
  try {
    // Make a GET request to the URL
    final response = await http.get(Uri.parse(url));

    // Check if the request was successful
    if (response.statusCode == 200) {
      // Return the response body as a string
      return response.body;
    } else {
      throw Exception('Failed to load data');
    }
  } catch (e) {
    print('Error fetching data: $e');
    return '';
  }
}