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:
45
lib/features/settings/models/household.dart
Normal file
45
lib/features/settings/models/household.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'household.g.dart';
|
||||
|
||||
@HiveType(typeId: 4)
|
||||
class Household extends HiveObject {
|
||||
@HiveField(0)
|
||||
late String id; // Unique household code
|
||||
|
||||
@HiveField(1)
|
||||
late String name;
|
||||
|
||||
@HiveField(2)
|
||||
late String ownerName; // Person who created the household
|
||||
|
||||
@HiveField(3)
|
||||
late DateTime createdAt;
|
||||
|
||||
@HiveField(4)
|
||||
List<String> members; // List of member names
|
||||
|
||||
Household({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.ownerName,
|
||||
DateTime? createdAt,
|
||||
List<String>? members,
|
||||
}) : createdAt = createdAt ?? DateTime.now(),
|
||||
members = members ?? [];
|
||||
|
||||
/// Generate a random household code
|
||||
static String generateCode() {
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
final random = DateTime.now().millisecondsSinceEpoch;
|
||||
var code = '';
|
||||
var seed = random;
|
||||
|
||||
for (var i = 0; i < 6; i++) {
|
||||
seed = (seed * 1103515245 + 12345) & 0x7fffffff;
|
||||
code += chars[seed % chars.length];
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user