Initial commit: Sage Kitchen Management App v1.0.0
✨ Features implemented: - Smart inventory tracking with Hive database - Barcode scanning with auto-populated product info - Multiple API fallbacks (Open Food Facts, UPCItemDB) - Smart expiration date predictions by category - Discord webhook notifications (persisted) - Custom sage leaf vector icon - Material Design 3 UI with sage green theme - Privacy Policy & Terms of Service - Local-first, privacy-focused architecture 🎨 UI/UX: - Home dashboard with inventory stats - Add Item screen with barcode integration - Inventory list with expiration indicators - Settings with persistent preferences - About section with legal docs 🔧 Technical: - Flutter 3.35.5 with Riverpod state management - Hive 2.2.3 for local database - Mobile scanner for barcode detection - Feature-first architecture 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
349
lib/features/inventory/screens/add_item_screen.dart
Normal file
349
lib/features/inventory/screens/add_item_screen.dart
Normal file
@@ -0,0 +1,349 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../core/constants/colors.dart';
|
||||
import '../models/food_item.dart';
|
||||
import '../controllers/inventory_controller.dart';
|
||||
import '../services/barcode_service.dart';
|
||||
import 'barcode_scanner_screen.dart';
|
||||
|
||||
/// Screen for adding a new food item to inventory
|
||||
class AddItemScreen extends ConsumerStatefulWidget {
|
||||
final String? scannedBarcode;
|
||||
|
||||
const AddItemScreen({super.key, this.scannedBarcode});
|
||||
|
||||
@override
|
||||
ConsumerState<AddItemScreen> createState() => _AddItemScreenState();
|
||||
}
|
||||
|
||||
class _AddItemScreenState extends ConsumerState<AddItemScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
// Form controllers
|
||||
final _nameController = TextEditingController();
|
||||
final _quantityController = TextEditingController(text: '1');
|
||||
final _unitController = TextEditingController();
|
||||
final _notesController = TextEditingController();
|
||||
|
||||
// Form values
|
||||
DateTime _purchaseDate = DateTime.now();
|
||||
DateTime _expirationDate = DateTime.now().add(const Duration(days: 7));
|
||||
Location _location = Location.fridge;
|
||||
String? _category;
|
||||
String? _barcode;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Pre-populate barcode if scanned and lookup product info
|
||||
if (widget.scannedBarcode != null) {
|
||||
_barcode = widget.scannedBarcode;
|
||||
_lookupProductInfo();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _lookupProductInfo() async {
|
||||
if (_barcode == null) return;
|
||||
|
||||
// Show loading
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Looking up product info...'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final productInfo = await BarcodeService.lookupBarcode(_barcode!);
|
||||
|
||||
if (productInfo != null && mounted) {
|
||||
setState(() {
|
||||
// Auto-fill product name
|
||||
_nameController.text = productInfo.name;
|
||||
|
||||
// Auto-fill category
|
||||
_category = productInfo.category;
|
||||
|
||||
// Set smart expiration date based on category
|
||||
final smartDays = BarcodeService.getSmartExpirationDays(productInfo.category);
|
||||
_expirationDate = DateTime.now().add(Duration(days: smartDays));
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('✨ Auto-filled: ${productInfo.name}'),
|
||||
backgroundColor: AppColors.success,
|
||||
),
|
||||
);
|
||||
} else if (mounted) {
|
||||
// Still keep the barcode, just let user fill in the rest
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Product not found in database. Barcode saved: $_barcode'),
|
||||
backgroundColor: AppColors.warning,
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_quantityController.dispose();
|
||||
_unitController.dispose();
|
||||
_notesController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _selectDate(BuildContext context, bool isExpiration) async {
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: isExpiration ? _expirationDate : _purchaseDate,
|
||||
firstDate: DateTime(2020),
|
||||
lastDate: DateTime(2030),
|
||||
);
|
||||
if (picked != null) {
|
||||
setState(() {
|
||||
if (isExpiration) {
|
||||
_expirationDate = picked;
|
||||
} else {
|
||||
_purchaseDate = picked;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _saveItem() async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
final item = FoodItem()
|
||||
..name = _nameController.text.trim()
|
||||
..barcode = _barcode
|
||||
..quantity = int.tryParse(_quantityController.text) ?? 1
|
||||
..unit = _unitController.text.trim().isEmpty
|
||||
? null
|
||||
: _unitController.text.trim()
|
||||
..purchaseDate = _purchaseDate
|
||||
..expirationDate = _expirationDate
|
||||
..location = _location
|
||||
..category = _category
|
||||
..notes = _notesController.text.trim().isEmpty
|
||||
? null
|
||||
: _notesController.text.trim()
|
||||
..lastModified = DateTime.now();
|
||||
|
||||
try {
|
||||
await ref.read(inventoryControllerProvider.notifier).addItem(item);
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('${item.name} added to inventory! 🎉'),
|
||||
backgroundColor: AppColors.success,
|
||||
),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Error saving item: $e'),
|
||||
backgroundColor: AppColors.error,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Add Item'),
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
// Name
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Item Name *',
|
||||
hintText: 'e.g., Milk, Ranch Dressing',
|
||||
prefixIcon: Icon(Icons.fastfood),
|
||||
),
|
||||
textCapitalization: TextCapitalization.words,
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return 'Please enter an item name';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Barcode Scanner
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
final barcode = await Navigator.push<String>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const BarcodeScannerScreen(),
|
||||
),
|
||||
);
|
||||
if (barcode != null) {
|
||||
setState(() {
|
||||
_barcode = barcode;
|
||||
});
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Barcode scanned: $barcode'),
|
||||
backgroundColor: AppColors.success,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.qr_code_scanner),
|
||||
label: Text(_barcode == null ? 'Scan Barcode' : 'Barcode: $_barcode'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: AppColors.primary,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Quantity & Unit
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: TextFormField(
|
||||
controller: _quantityController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Quantity *',
|
||||
prefixIcon: Icon(Icons.numbers),
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Required';
|
||||
}
|
||||
if (int.tryParse(value) == null) {
|
||||
return 'Invalid';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: TextFormField(
|
||||
controller: _unitController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Unit',
|
||||
hintText: 'bottles, lbs, oz',
|
||||
prefixIcon: Icon(Icons.scale),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Location
|
||||
DropdownButtonFormField<Location>(
|
||||
value: _location,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Location *',
|
||||
prefixIcon: Icon(Icons.location_on),
|
||||
),
|
||||
items: Location.values.map((location) {
|
||||
return DropdownMenuItem(
|
||||
value: location,
|
||||
child: Text('${location.emoji} ${location.displayName}'),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() => _location = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Category
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Category (Optional)',
|
||||
hintText: 'Dairy, Produce, Condiments',
|
||||
prefixIcon: Icon(Icons.category),
|
||||
),
|
||||
textCapitalization: TextCapitalization.words,
|
||||
onChanged: (value) => _category = value.isEmpty ? null : value,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Purchase Date
|
||||
ListTile(
|
||||
title: const Text('Purchase Date'),
|
||||
subtitle: Text(DateFormat('MMM dd, yyyy').format(_purchaseDate)),
|
||||
leading: const Icon(Icons.shopping_cart, color: AppColors.primary),
|
||||
trailing: const Icon(Icons.calendar_today),
|
||||
onTap: () => _selectDate(context, false),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Expiration Date
|
||||
ListTile(
|
||||
title: const Text('Expiration Date'),
|
||||
subtitle: Text(DateFormat('MMM dd, yyyy').format(_expirationDate)),
|
||||
leading: const Icon(Icons.event_busy, color: AppColors.warning2),
|
||||
trailing: const Icon(Icons.calendar_today),
|
||||
onTap: () => _selectDate(context, true),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Notes
|
||||
TextFormField(
|
||||
controller: _notesController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Notes (Optional)',
|
||||
hintText: 'Any additional details',
|
||||
prefixIcon: Icon(Icons.note),
|
||||
),
|
||||
maxLines: 3,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// Save Button
|
||||
ElevatedButton.icon(
|
||||
onPressed: _saveItem,
|
||||
icon: const Icon(Icons.save),
|
||||
label: const Text('Save Item'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
154
lib/features/inventory/screens/barcode_scanner_screen.dart
Normal file
154
lib/features/inventory/screens/barcode_scanner_screen.dart
Normal file
@@ -0,0 +1,154 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import '../../../core/constants/colors.dart';
|
||||
import 'add_item_screen.dart';
|
||||
|
||||
class BarcodeScannerScreen extends StatefulWidget {
|
||||
const BarcodeScannerScreen({super.key});
|
||||
|
||||
@override
|
||||
State<BarcodeScannerScreen> createState() => _BarcodeScannerScreenState();
|
||||
}
|
||||
|
||||
class _BarcodeScannerScreenState extends State<BarcodeScannerScreen> {
|
||||
final MobileScannerController controller = MobileScannerController();
|
||||
bool _isScanning = true;
|
||||
String? _scannedCode;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onBarcodeDetected(String barcode) {
|
||||
if (!_isScanning) return;
|
||||
|
||||
setState(() {
|
||||
_isScanning = false;
|
||||
_scannedCode = barcode;
|
||||
});
|
||||
|
||||
// Show success and navigate to Add Item screen
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (mounted) {
|
||||
// Pop scanner and push Add Item screen with barcode
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => AddItemScreen(scannedBarcode: barcode),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Scan Barcode'),
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.flash_on),
|
||||
onPressed: () => controller.toggleTorch(),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.cameraswitch),
|
||||
onPressed: () => controller.switchCamera(),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
MobileScanner(
|
||||
controller: controller,
|
||||
onDetect: (capture) {
|
||||
final List<Barcode> barcodes = capture.barcodes;
|
||||
if (barcodes.isNotEmpty && _isScanning) {
|
||||
final barcode = barcodes.first.rawValue ?? '';
|
||||
if (barcode.isNotEmpty) {
|
||||
_onBarcodeDetected(barcode);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
// Overlay with scan area guide
|
||||
Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
height: 250,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: _scannedCode != null ? AppColors.success : AppColors.primary,
|
||||
width: 3,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: _scannedCode != null
|
||||
? Container(
|
||||
color: AppColors.success.withOpacity(0.3),
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.check_circle,
|
||||
color: Colors.white,
|
||||
size: 64,
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
// Instructions at bottom
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.7),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
_scannedCode != null ? Icons.check_circle : Icons.qr_code_scanner,
|
||||
color: Colors.white,
|
||||
size: 48,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_scannedCode != null
|
||||
? 'Barcode Scanned!'
|
||||
: 'Position the barcode inside the frame',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_scannedCode ?? 'The barcode will be scanned automatically',
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 14,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
228
lib/features/inventory/screens/inventory_screen.dart
Normal file
228
lib/features/inventory/screens/inventory_screen.dart
Normal file
@@ -0,0 +1,228 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../core/constants/colors.dart';
|
||||
import '../models/food_item.dart';
|
||||
import '../controllers/inventory_controller.dart';
|
||||
import 'add_item_screen.dart';
|
||||
|
||||
/// Screen displaying all inventory items
|
||||
class InventoryScreen extends ConsumerWidget {
|
||||
const InventoryScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final inventoryState = ref.watch(inventoryControllerProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('📦 Inventory'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () {
|
||||
// TODO: Search functionality
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: inventoryState.when(
|
||||
data: (items) {
|
||||
if (items.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.inventory_2_outlined,
|
||||
size: 80,
|
||||
color: Colors.grey.shade300,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'No items yet!',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Tap + to add your first item',
|
||||
style: TextStyle(color: Colors.grey.shade500),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Sort by expiration date (soonest first)
|
||||
final sortedItems = List<FoodItem>.from(items)
|
||||
..sort((a, b) => a.expirationDate.compareTo(b.expirationDate));
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: sortedItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = sortedItems[index];
|
||||
return _buildInventoryCard(context, ref, item);
|
||||
},
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) => Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 48, color: AppColors.error),
|
||||
const SizedBox(height: 16),
|
||||
Text('Error: $error'),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () => ref.refresh(inventoryControllerProvider),
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const AddItemScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Add Item'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInventoryCard(
|
||||
BuildContext context, WidgetRef ref, FoodItem item) {
|
||||
final daysUntil = item.daysUntilExpiration;
|
||||
final status = item.expirationStatus;
|
||||
final statusColor = Color(status.colorValue);
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: statusColor.withOpacity(0.2),
|
||||
child: Text(
|
||||
item.location.emoji,
|
||||
style: const TextStyle(fontSize: 24),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
item.name,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${item.location.displayName} • ${item.quantity} ${item.unit ?? "items"}',
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
item.isExpired
|
||||
? Icons.warning
|
||||
: item.isExpiringSoon
|
||||
? Icons.schedule
|
||||
: Icons.check_circle,
|
||||
size: 16,
|
||||
color: statusColor,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
item.isExpired
|
||||
? 'Expired ${-daysUntil} days ago'
|
||||
: 'Expires in $daysUntil days',
|
||||
style: TextStyle(
|
||||
color: statusColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'Exp: ${DateFormat('MMM dd, yyyy').format(item.expirationDate)}',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: PopupMenuButton<String>(
|
||||
onSelected: (value) async {
|
||||
if (value == 'delete') {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Delete Item'),
|
||||
content: Text('Delete ${item.name}?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text(
|
||||
'Delete',
|
||||
style: TextStyle(color: AppColors.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirm == true) {
|
||||
await ref
|
||||
.read(inventoryControllerProvider.notifier)
|
||||
.deleteItem(item.key);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('${item.name} deleted'),
|
||||
backgroundColor: AppColors.error,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
const PopupMenuItem(
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete, color: AppColors.error),
|
||||
SizedBox(width: 8),
|
||||
Text('Delete'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user