Files
Sage/lib/features/inventory/screens/inventory_screen.dart
Dani 7ab641a3c8 v1.3.0+4: FOSS Compliance + Dark Mode + Enhanced Settings
 Major Features:
- Dark mode toggle with app-wide theme switching
- Sort inventory by Expiration Date, Name, or Location
- Toggle between Grid and List view for inventory
- Export inventory data to CSV with share functionality
- Custom sage leaf app icon with adaptive icon support

🔄 FOSS Compliance (F-Droid Ready):
- Replaced Firebase with Supabase (open-source backend)
- Anonymous authentication (no user accounts required)
- Cloud-first with hosted Supabase as default
- Optional self-hosting support
- 100% FOSS-compliant dependencies

🎨 UI/UX Improvements:
- Dynamic version display from package.json (was hardcoded)
- Added edit buttons for household and user names
- Removed non-functional search button
- Replaced Recipes placeholder with Settings button
- Improved settings organization with clear sections

📦 Dependencies:
Added:
- supabase_flutter: ^2.8.4 (FOSS backend sync)
- package_info_plus: ^8.1.0 (dynamic version)
- csv: ^6.0.0 (data export)
- share_plus: ^10.1.2 (file sharing)
- image: ^4.5.4 (dev, icon generation)

Removed:
- firebase_core (replaced with Supabase)
- cloud_firestore (replaced with Supabase)

🗑️ Cleanup:
- Removed Firebase setup files and google-services.json
- Removed unimplemented features (Recipes, Search)
- Removed firebase_household_service.dart
- Removed inventory_sync_service.dart (replaced with Supabase)

📄 New Files:
- lib/features/household/services/supabase_household_service.dart
- web/privacy-policy.html (Play Store requirement)
- web/terms-of-service.html (Play Store requirement)
- PLAY_STORE_LISTING.md (marketing copy)
- tool/generate_icons.dart (icon generation script)
- assets/icon/sage_leaf.png (1024x1024)
- assets/icon/sage_leaf_foreground.png (adaptive icon)

🐛 Bug Fixes:
- Fixed version display showing hardcoded "1.0.0"
- Fixed Sort By and Default View showing static text
- Fixed ConsumerWidget build signatures
- Fixed Location.displayName import issues
- Added clearAllData method to Hive database

📊 Stats: +1,728 additions, -756 deletions across 42 files

🤖 Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-04 22:27:42 -04:00

221 lines
7.0 KiB
Dart

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'),
),
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'),
],
),
),
],
),
),
);
}
}