import 'dart:io'; import 'package:flutter/material.dart'; import '../models/fuel_entry.dart'; import '../screens/receipt_image_screen.dart'; /// A fuel entry's receipt as a tappable thumbnail: the local photo if one's /// still on-device, a cloud icon (tap to download-and-view) if it's been /// uploaded and the local copy cleared, or a plain placeholder if there's /// no receipt at all. Shared by [VehicleDetailScreen]'s entry list, the /// cross-vehicle Receipts tab, [ReceiptDetailScreen] (at a larger [size], /// as its primary preview), and [EditFuelEntryScreen] so all four present a /// receipt the same way. /// /// Tapping it opens the full-screen photo viewer by default; pass [onTap] /// to send it somewhere else instead (e.g. the list rows send it to /// [ReceiptDetailScreen] instead of straight to the photo). class ReceiptThumbnail extends StatelessWidget { final FuelEntry entry; final double size; final VoidCallback? onTap; const ReceiptThumbnail({super.key, required this.entry, this.size = 48, this.onTap}); @override Widget build(BuildContext context) { if (entry.receiptImagePath != null) { return GestureDetector( onTap: onTap ?? () => Navigator.of(context).push( MaterialPageRoute( builder: (_) => ReceiptImageScreen(localImagePath: entry.receiptImagePath), ), ), child: ClipRRect( borderRadius: BorderRadius.circular(6), child: Image.file( File(entry.receiptImagePath!), width: size, height: size, fit: BoxFit.cover, ), ), ); } if (entry.isReceiptUploadedToDrive) { return GestureDetector( onTap: onTap ?? () => Navigator.of(context).push( MaterialPageRoute( builder: (_) => ReceiptImageScreen(driveFileId: entry.receiptDriveFileId), ), ), child: CircleAvatar(radius: size / 2, child: Icon(Icons.cloud_outlined, size: size * 0.5)), ); } final placeholder = CircleAvatar(radius: size / 2, child: Icon(Icons.receipt_long, size: size * 0.5)); return onTap == null ? placeholder : GestureDetector(onTap: onTap, child: placeholder); } }