✨ 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>
575 lines
18 KiB
Dart
575 lines
18 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import '../../../core/constants/colors.dart';
|
|
import '../../../data/local/hive_database.dart';
|
|
import '../../household/services/supabase_household_service.dart';
|
|
import '../models/app_settings.dart';
|
|
import '../models/household.dart';
|
|
|
|
class HouseholdScreen extends StatefulWidget {
|
|
const HouseholdScreen({super.key});
|
|
|
|
@override
|
|
State<HouseholdScreen> createState() => _HouseholdScreenState();
|
|
}
|
|
|
|
class _HouseholdScreenState extends State<HouseholdScreen> {
|
|
final _supabaseService = SupabaseHouseholdService();
|
|
AppSettings? _settings;
|
|
Household? _household;
|
|
bool _isLoading = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadData();
|
|
}
|
|
|
|
Future<void> _loadData() async {
|
|
final settings = await HiveDatabase.getSettings();
|
|
Household? household;
|
|
|
|
if (settings.currentHouseholdId != null) {
|
|
try {
|
|
// Load from Supabase
|
|
household = await _supabaseService.getHousehold(settings.currentHouseholdId!);
|
|
} catch (e) {
|
|
// Household not found
|
|
}
|
|
}
|
|
|
|
setState(() {
|
|
_settings = settings;
|
|
_household = household;
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
|
|
Future<void> _createHousehold() async {
|
|
if (_settings!.userName == null || _settings!.userName!.isEmpty) {
|
|
_showNameInputDialog();
|
|
return;
|
|
}
|
|
|
|
final nameController = TextEditingController();
|
|
|
|
final result = await showDialog<String>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Create Household'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
controller: nameController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Household Name',
|
|
hintText: 'e.g., Smith Family, Roommates',
|
|
),
|
|
textCapitalization: TextCapitalization.words,
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, nameController.text),
|
|
child: const Text('Create'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (result != null && result.isNotEmpty) {
|
|
try {
|
|
// Create household in Firebase
|
|
final household = await _supabaseService.createHousehold(result, _settings!.userName!);
|
|
|
|
// Also save to local Hive for offline access
|
|
await HiveDatabase.saveHousehold(household);
|
|
|
|
_settings!.currentHouseholdId = household.id;
|
|
await _settings!.save();
|
|
|
|
await _loadData();
|
|
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Household created! Code: ${household.id}'),
|
|
backgroundColor: AppColors.success,
|
|
duration: const Duration(seconds: 5),
|
|
),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Error creating household: ${e.toString().contains('firebase') ? 'Firebase not configured. See FIREBASE_SETUP.md' : e.toString()}'),
|
|
backgroundColor: AppColors.error,
|
|
duration: const Duration(seconds: 5),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _joinHousehold() async {
|
|
if (_settings!.userName == null || _settings!.userName!.isEmpty) {
|
|
_showNameInputDialog();
|
|
return;
|
|
}
|
|
|
|
final codeController = TextEditingController();
|
|
|
|
final result = await showDialog<String>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Join Household'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Text('Enter the household code shared with you:'),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: codeController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Household Code',
|
|
hintText: '6-character code',
|
|
),
|
|
textCapitalization: TextCapitalization.characters,
|
|
maxLength: 6,
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, codeController.text),
|
|
child: const Text('Join'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (result != null && result.isNotEmpty) {
|
|
try {
|
|
final code = result.toUpperCase();
|
|
|
|
// Join household in Supabase
|
|
final household = await _supabaseService.joinHousehold(code, _settings!.userName!);
|
|
|
|
// Save to local Hive for offline access
|
|
await HiveDatabase.saveHousehold(household);
|
|
|
|
_settings!.currentHouseholdId = household.id;
|
|
await _settings!.save();
|
|
|
|
await _loadData();
|
|
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Joined ${household.name}!'),
|
|
backgroundColor: AppColors.success,
|
|
),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Error joining household: $e'),
|
|
backgroundColor: AppColors.error,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _showNameInputDialog() async {
|
|
final nameController = TextEditingController(text: _settings!.userName);
|
|
|
|
final result = await showDialog<String>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Enter Your Name'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Text('Please enter your name to use household sharing:'),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: nameController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Your Name',
|
|
hintText: 'e.g., Sarah',
|
|
),
|
|
textCapitalization: TextCapitalization.words,
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, nameController.text),
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (result != null && result.isNotEmpty) {
|
|
_settings!.userName = result;
|
|
await _settings!.save();
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
Future<void> _editHouseholdName() async {
|
|
final nameController = TextEditingController(text: _household!.name);
|
|
|
|
final result = await showDialog<String>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Edit Household Name'),
|
|
content: TextField(
|
|
controller: nameController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Household Name',
|
|
hintText: 'e.g., Smith Family',
|
|
),
|
|
textCapitalization: TextCapitalization.words,
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, nameController.text),
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (result != null && result.isNotEmpty && result != _household!.name) {
|
|
try {
|
|
// Update in Supabase
|
|
await _supabaseService.updateHouseholdName(_household!.id, result);
|
|
|
|
// Update local
|
|
_household!.name = result;
|
|
await HiveDatabase.saveHousehold(_household!);
|
|
|
|
setState(() {});
|
|
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Household name updated!'),
|
|
backgroundColor: AppColors.success,
|
|
),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Error updating name: $e'),
|
|
backgroundColor: AppColors.error,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _leaveHousehold() async {
|
|
final confirm = await showDialog<bool>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Leave Household?'),
|
|
content: const Text(
|
|
'You will no longer see items from this household. You can rejoin later with the household code.',
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
child: const Text(
|
|
'Leave',
|
|
style: TextStyle(color: AppColors.error),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (confirm == true && _household != null) {
|
|
// Leave household in Firebase
|
|
await _supabaseService.leaveHousehold(_household!.id, _settings!.userName!);
|
|
|
|
_settings!.currentHouseholdId = null;
|
|
await _settings!.save();
|
|
|
|
await _loadData();
|
|
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Left household'),
|
|
backgroundColor: AppColors.success,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (_isLoading) {
|
|
return const Scaffold(
|
|
body: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Household Sharing'),
|
|
backgroundColor: AppColors.primary,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
body: _household == null ? _buildNoHousehold() : _buildHouseholdInfo(),
|
|
);
|
|
}
|
|
|
|
Widget _buildNoHousehold() {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(
|
|
Icons.group,
|
|
size: 80,
|
|
color: AppColors.primary,
|
|
),
|
|
const SizedBox(height: 24),
|
|
const Text(
|
|
'Share Your Inventory',
|
|
style: TextStyle(
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'Create or join a household to share your kitchen inventory with family or roommates!',
|
|
style: TextStyle(fontSize: 16),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 48),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton.icon(
|
|
onPressed: _createHousehold,
|
|
icon: const Icon(Icons.add),
|
|
label: const Text('Create Household'),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColors.primary,
|
|
foregroundColor: Colors.white,
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: OutlinedButton.icon(
|
|
onPressed: _joinHousehold,
|
|
icon: const Icon(Icons.login),
|
|
label: const Text('Join Household'),
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: AppColors.primary,
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHouseholdInfo() {
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
const Icon(Icons.home, color: AppColors.primary, size: 32),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
_household!.name,
|
|
style: const TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.edit, size: 20),
|
|
onPressed: _editHouseholdName,
|
|
tooltip: 'Edit household name',
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
'You: ${_settings!.userName ?? "Not set"}',
|
|
style: TextStyle(
|
|
color: Colors.grey[600],
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.edit, size: 18),
|
|
onPressed: _showNameInputDialog,
|
|
tooltip: 'Edit your name',
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const Divider(height: 32),
|
|
const Text(
|
|
'Household Code',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.primary.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Text(
|
|
_household!.id,
|
|
style: const TextStyle(
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
letterSpacing: 4,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
IconButton(
|
|
onPressed: () {
|
|
Clipboard.setData(ClipboardData(text: _household!.id));
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Code copied to clipboard!'),
|
|
duration: Duration(seconds: 2),
|
|
),
|
|
);
|
|
},
|
|
icon: const Icon(Icons.copy),
|
|
color: AppColors.primary,
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
const Text(
|
|
'Share this code with others to let them join your household',
|
|
style: TextStyle(fontSize: 12),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'Members',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
..._household!.members.map((member) => Card(
|
|
child: ListTile(
|
|
leading: CircleAvatar(
|
|
backgroundColor: AppColors.primary,
|
|
child: Text(
|
|
member[0].toUpperCase(),
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
),
|
|
title: Text(member),
|
|
trailing: member == _household!.ownerName
|
|
? const Chip(
|
|
label: Text('Owner'),
|
|
backgroundColor: AppColors.primary,
|
|
labelStyle: TextStyle(color: Colors.white),
|
|
)
|
|
: null,
|
|
),
|
|
)),
|
|
const SizedBox(height: 24),
|
|
OutlinedButton.icon(
|
|
onPressed: _leaveHousehold,
|
|
icon: const Icon(Icons.exit_to_app),
|
|
label: const Text('Leave Household'),
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: AppColors.error,
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|