Add household sharing feature
✨ Features: - Create household with 6-character shareable code - Join existing household with code - View household members and owner - Leave household functionality - Automatic inventory filtering by household - Persistent household settings across app updates 🔧 Technical changes: - Added Household model with Hive adapter (typeId: 4) - Updated AppSettings with userName and currentHouseholdId fields - Modified InventoryRepository to filter items by household - Updated Add Item screen to set householdId on new items - Added HouseholdScreen with full CRUD operations - Integrated household sharing into Settings navigation 🎯 Behavior: - Users not in a household see only their personal items - Users in a household see shared household items - New items automatically tagged with current household 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import '../../features/inventory/models/food_item.dart';
|
||||
import '../../features/settings/models/app_settings.dart';
|
||||
import '../../features/settings/models/household.dart';
|
||||
|
||||
/// Singleton class to manage Hive database
|
||||
class HiveDatabase {
|
||||
@@ -17,6 +18,7 @@ class HiveDatabase {
|
||||
Hive.registerAdapter(LocationAdapter());
|
||||
Hive.registerAdapter(ExpirationStatusAdapter());
|
||||
Hive.registerAdapter(AppSettingsAdapter());
|
||||
Hive.registerAdapter(HouseholdAdapter());
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
@@ -48,6 +50,29 @@ class HiveDatabase {
|
||||
return box.getAt(0)!;
|
||||
}
|
||||
|
||||
/// Get the households box
|
||||
static Future<Box<Household>> getHouseholdsBox() async {
|
||||
if (!Hive.isBoxOpen('households')) {
|
||||
return await Hive.openBox<Household>('households');
|
||||
}
|
||||
return Hive.box<Household>('households');
|
||||
}
|
||||
|
||||
/// Get household by ID
|
||||
static Future<Household?> getHousehold(String id) async {
|
||||
final box = await getHouseholdsBox();
|
||||
return box.values.firstWhere(
|
||||
(h) => h.id == id,
|
||||
orElse: () => throw Exception('Household not found'),
|
||||
);
|
||||
}
|
||||
|
||||
/// Save household
|
||||
static Future<void> saveHousehold(Household household) async {
|
||||
final box = await getHouseholdsBox();
|
||||
await box.put(household.id, household);
|
||||
}
|
||||
|
||||
/// Clear all data
|
||||
static Future<void> clearAll() async {
|
||||
final box = await getFoodBox();
|
||||
|
Reference in New Issue
Block a user