getAiImageFile static method
Future<File>
getAiImageFile({
- required AiTextClient aiClient,
- String? prompt,
- Duration timeout = const Duration(seconds: 25),
AI image -> File: downloads an image URL (from Picsum or AI provider).
Implementation
static Future<File> getAiImageFile({
required AiTextClient aiClient,
String? prompt,
Duration timeout = const Duration(seconds: 25),
}) async {
// Get a URL from the AI client (or picsum fallback)
final url = await aiClient.generateImageUrl(
prompt: prompt ?? 'A modern office workspace with natural light');
final resp = await http.get(url).timeout(timeout);
if (resp.statusCode >= 200 && resp.statusCode < 300) {
final tempDir = await getTemporaryDirectory();
final file = File(
'${tempDir.path}/ai_${DateTime.now().millisecondsSinceEpoch}.jpg');
await file.writeAsBytes(resp.bodyBytes);
return file;
} else {
// If download fails, fallback to a local asset
return getFakeImageFile();
}
}