A whole bunch of changes
This commit is contained in:
parent
901ec678a3
commit
956231048e
122 changed files with 5442 additions and 914 deletions
108
lib/widgets/hero_banner.dart
Normal file
108
lib/widgets/hero_banner.dart
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// Green gradient hero banner background shared by every screen that shows
|
||||
/// a totals summary (Receipts, Vehicle Detail) — callers supply their own
|
||||
/// stat row / controls as [child], keeping the container/gradient styling
|
||||
/// itself in one place.
|
||||
class HeroBanner extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
const HeroBanner({super.key, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: AppTheme.heroGradient(context),
|
||||
),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A single label/value pair inside a [HeroBanner], e.g. "Total Gallons".
|
||||
class HeroStat extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
final bool alignEnd;
|
||||
|
||||
const HeroStat({super.key, required this.label, required this.value, required this.alignEnd});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final textAlign = alignEnd ? TextAlign.end : TextAlign.start;
|
||||
return Column(
|
||||
crossAxisAlignment: alignEnd ? CrossAxisAlignment.end : CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
textAlign: textAlign,
|
||||
style: TextStyle(
|
||||
color: AppTheme.heroTextSecondary(context),
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value,
|
||||
textAlign: textAlign,
|
||||
style: const TextStyle(
|
||||
color: AppTheme.heroText,
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w800,
|
||||
letterSpacing: -0.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The icon + two-stat row shared by every hero banner: gallons on the
|
||||
/// left, the hero icon in the middle, cost on the right.
|
||||
class HeroStatsRow extends StatelessWidget {
|
||||
final String gallonsValue;
|
||||
final String costValue;
|
||||
final String gallonsLabel;
|
||||
final String costLabel;
|
||||
|
||||
const HeroStatsRow({
|
||||
super.key,
|
||||
required this.gallonsValue,
|
||||
required this.costValue,
|
||||
this.gallonsLabel = 'Total Gallons',
|
||||
this.costLabel = 'Total Fuel Cost',
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: HeroStat(label: gallonsLabel, value: gallonsValue, alignEnd: false)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
// Tall enough to extend past the bottom of the label+value text
|
||||
// next to it, not just match the label's height — width scales
|
||||
// automatically from the source's own aspect ratio since only
|
||||
// height is given.
|
||||
child: Image.asset(
|
||||
'assets/icon/hero_icon.png',
|
||||
height: 58,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
Expanded(child: HeroStat(label: costLabel, value: costValue, alignEnd: true)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,13 +4,46 @@ import 'package:image_picker/image_picker.dart';
|
|||
/// Bottom sheet letting the user pick a photo from the camera or their
|
||||
/// existing library. Shared by any screen that needs to snap or choose a
|
||||
/// photo (receipt capture, VIN scanning) so the choice looks and behaves
|
||||
/// the same everywhere.
|
||||
Future<ImageSource?> chooseImageSource(BuildContext context) {
|
||||
/// the same everywhere. Pass [heading] to label what the photo is for
|
||||
/// (e.g. receipt capture passes "Receipt From") — omitted by callers where
|
||||
/// that's already obvious from context. [onInfoTap], if given, adds an
|
||||
/// info button next to [heading] (e.g. VIN scanning uses it to explain
|
||||
/// where to find a VIN); ignored if [heading] is null, since there'd be
|
||||
/// nowhere to put it.
|
||||
Future<ImageSource?> chooseImageSource(
|
||||
BuildContext context, {
|
||||
String? heading,
|
||||
VoidCallback? onInfoTap,
|
||||
}) {
|
||||
return showModalBottomSheet<ImageSource>(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
child: Wrap(
|
||||
children: [
|
||||
if (heading != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 8, 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
heading,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.labelLarge
|
||||
?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
if (onInfoTap != null)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.info_outline),
|
||||
iconSize: 20,
|
||||
tooltip: 'Where do I find this?',
|
||||
onPressed: onInfoTap,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.camera_alt_outlined),
|
||||
title: const Text('Take Photo'),
|
||||
|
|
|
|||
115
lib/widgets/receipt_capture.dart
Normal file
115
lib/widgets/receipt_capture.dart
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../screens/confirm_fuel_entry_screen.dart';
|
||||
import '../services/app_state.dart';
|
||||
import '../services/ocr_service.dart';
|
||||
import '../services/receipt_parser.dart';
|
||||
import 'image_source_sheet.dart';
|
||||
|
||||
/// Long edge and JPEG quality a receipt photo is downscaled to unless
|
||||
/// "keep max quality" is on — a receipt is a photo of small printed text,
|
||||
/// not something that benefits from a multi-megapixel original, and this
|
||||
/// keeps typical files in the low hundreds of KB instead of several MB.
|
||||
const receiptImageMaxDimension = 1600.0;
|
||||
const receiptImageQuality = 70;
|
||||
|
||||
/// Shared by [VehicleDetailScreen]'s "Log Fuel Receipt" button and the
|
||||
/// Receipts tab's "+" action: pick a photo, OCR it, and — unless the
|
||||
/// receipt looks like it's from outside Missouri, in which case the user
|
||||
/// gets a chance to back out first — hand off to [ConfirmFuelEntryScreen]
|
||||
/// for [vehicleId].
|
||||
Future<void> captureReceiptForVehicle(BuildContext context, String vehicleId) async {
|
||||
final source = await chooseImageSource(context, heading: 'Receipt From');
|
||||
if (source == null || !context.mounted) return;
|
||||
|
||||
final keepMaxQuality = context.read<AppState>().keepMaxQualityReceiptPhotos;
|
||||
final picker = ImagePicker();
|
||||
XFile? photo;
|
||||
try {
|
||||
photo = await picker.pickImage(
|
||||
source: source,
|
||||
imageQuality: keepMaxQuality ? null : receiptImageQuality,
|
||||
maxWidth: keepMaxQuality ? null : receiptImageMaxDimension,
|
||||
maxHeight: keepMaxQuality ? null : receiptImageMaxDimension,
|
||||
);
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
final sourceLabel = source == ImageSource.camera ? 'camera' : 'photo library';
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Could not open $sourceLabel: $e')),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (photo == null) return;
|
||||
|
||||
final imageFile = File(photo.path);
|
||||
|
||||
if (!context.mounted) return;
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => const Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
|
||||
final ocrService = OcrService();
|
||||
String recognizedText = '';
|
||||
try {
|
||||
recognizedText = await ocrService.recognizeText(imageFile);
|
||||
} catch (_) {
|
||||
recognizedText = '';
|
||||
} finally {
|
||||
ocrService.dispose();
|
||||
}
|
||||
|
||||
final parsed = ReceiptParser.parse(recognizedText);
|
||||
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).pop(); // close the OCR loading spinner
|
||||
|
||||
final state = parsed.state;
|
||||
if (state != null && state != 'MO') {
|
||||
final proceed = await _confirmNonMissouriPurchase(context, state);
|
||||
if (!proceed || !context.mounted) return;
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ConfirmFuelEntryScreen(
|
||||
vehicleId: vehicleId,
|
||||
imageFile: imageFile,
|
||||
parsed: parsed,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Missouri's fuel tax refund only applies to fuel bought in Missouri —
|
||||
/// warn if the receipt's address is somewhere else, and let the user
|
||||
/// decide whether to log it anyway (e.g. it might still be worth tracking
|
||||
/// for other reasons even if it won't qualify for a refund).
|
||||
Future<bool> _confirmNonMissouriPurchase(BuildContext context, String stateCode) async {
|
||||
final stateName = usStateNames[stateCode] ?? stateCode;
|
||||
final proceed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Non-Missouri Purchase'),
|
||||
content: Text(
|
||||
'This receipt looks like it\'s from a gas station in $stateName. '
|
||||
'The Missouri fuel tax refund only applies to fuel purchased in '
|
||||
'Missouri.\n\nDo you still want to add this entry?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.of(context).pop(false), child: const Text('No')),
|
||||
FilledButton(onPressed: () => Navigator.of(context).pop(true), child: const Text('Yes')),
|
||||
],
|
||||
),
|
||||
);
|
||||
return proceed ?? false;
|
||||
}
|
||||
61
lib/widgets/receipt_thumbnail.dart
Normal file
61
lib/widgets/receipt_thumbnail.dart
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue