loadFileFromGitHub function
Implementation
Future<String> loadFileFromGitHub({
required String username,
required String repo,
String branch = 'main',
required String filePath,
}) async {
// Construct the raw file URL
final url =
'https://raw.githubusercontent.com/$username/$repo/$branch/$filePath';
try {
// Send the GET request to fetch the file
final response = await http.get(Uri.parse(url));
// Check if the request was successful
if (response.statusCode == 200) {
return utf8.decode(response.bodyBytes); // Return the file content
} else {
return 'Failed to load file: HTTP ${response.statusCode}';
}
} catch (e) {
return 'Error: $e';
}
}