downloadThemeCss static method
Download the latest Tailwind CSS theme file from GitHub
Implementation
static Future<String> downloadThemeCss([String? customUrl]) async {
// Use the latest Tailwind CSS theme URL by default
const defaultThemeUrl =
'https://raw.githubusercontent.com/tailwindlabs/tailwindcss/6c30d5ea3a221837ff55f6c425fb4f00f72b0941/packages/tailwindcss/theme.css';
final themeUrl = customUrl ?? defaultThemeUrl;
print('Downloading Tailwind CSS theme from GitHub...');
print('URL: $themeUrl');
try {
final client = HttpClient();
final request = await client.getUrl(Uri.parse(themeUrl));
final response = await request.close();
if (response.statusCode == 200) {
final bytes = await response.fold<Uint8List>(
Uint8List(0),
(previous, element) => Uint8List.fromList([...previous, ...element]),
);
final cssContent = utf8.decode(bytes);
print('Successfully downloaded theme.css (${bytes.length} bytes)');
return cssContent;
} else {
throw Exception(
'Failed to download theme.css: HTTP ${response.statusCode}',
);
}
} catch (e) {
throw Exception('Error downloading theme.css: $e');
}
}