Refactor: Implement multi-item inventory for Pad Tracker and dynamic navigation

This commit is contained in:
2026-01-02 18:10:50 -06:00
parent 56683f5407
commit 8772b56f36
44 changed files with 3515 additions and 781 deletions

View File

@@ -6,6 +6,49 @@ part of 'user_profile.dart';
// TypeAdapterGenerator
// **************************************************************************
class SupplyItemAdapter extends TypeAdapter<SupplyItem> {
@override
final int typeId = 12;
@override
SupplyItem read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return SupplyItem(
brand: fields[0] as String,
type: fields[1] as PadType,
absorbency: fields[2] as int,
count: fields[3] as int,
);
}
@override
void write(BinaryWriter writer, SupplyItem obj) {
writer
..writeByte(4)
..writeByte(0)
..write(obj.brand)
..writeByte(1)
..write(obj.type)
..writeByte(2)
..write(obj.absorbency)
..writeByte(3)
..write(obj.count);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is SupplyItemAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class UserProfileAdapter extends TypeAdapter<UserProfile> {
@override
final int typeId = 2;
@@ -19,14 +62,15 @@ class UserProfileAdapter extends TypeAdapter<UserProfile> {
return UserProfile(
id: fields[0] as String,
name: fields[1] as String,
relationshipStatus: fields[2] as RelationshipStatus,
relationshipStatus: fields[2] == null
? RelationshipStatus.single
: fields[2] as RelationshipStatus,
fertilityGoal: fields[3] as FertilityGoal?,
averageCycleLength: fields[4] as int,
averagePeriodLength: fields[5] as int,
averageCycleLength: fields[4] == null ? 28 : fields[4] as int,
averagePeriodLength: fields[5] == null ? 5 : fields[5] as int,
lastPeriodStartDate: fields[6] as DateTime?,
notificationsEnabled: fields[7] as bool,
devotionalTime: fields[8] as String?,
hasCompletedOnboarding: fields[9] as bool,
notificationsEnabled: fields[8] == null ? true : fields[8] as bool,
hasCompletedOnboarding: fields[9] == null ? false : fields[9] as bool,
createdAt: fields[10] as DateTime,
updatedAt: fields[11] as DateTime,
partnerName: fields[12] as String?,
@@ -46,13 +90,26 @@ class UserProfileAdapter extends TypeAdapter<UserProfile> {
shareEnergyLevels: fields[24] == null ? true : fields[24] as bool,
shareSleep: fields[25] == null ? true : fields[25] as bool,
shareIntimacy: fields[26] == null ? true : fields[26] as bool,
isPadTrackingEnabled: fields[27] == null ? false : fields[27] as bool,
typicalFlowIntensity: fields[28] as int?,
padBrand: fields[29] as String?,
padAbsorbency: fields[30] as int?,
padInventoryCount: fields[31] == null ? 0 : fields[31] as int,
lowInventoryThreshold: fields[32] == null ? 5 : fields[32] as int,
isAutoInventoryEnabled: fields[33] == null ? true : fields[33] as bool,
lastInventoryUpdate: fields[34] as DateTime?,
notifyPeriodEstimate: fields[35] == null ? true : fields[35] as bool,
notifyPeriodStart: fields[36] == null ? true : fields[36] as bool,
notifyLowSupply: fields[37] == null ? true : fields[37] as bool,
lastPadChangeTime: fields[7] as DateTime?,
padSupplies: (fields[38] as List?)?.cast<SupplyItem>(),
);
}
@override
void write(BinaryWriter writer, UserProfile obj) {
writer
..writeByte(26)
..writeByte(38)
..writeByte(0)
..write(obj.id)
..writeByte(1)
@@ -68,9 +125,9 @@ class UserProfileAdapter extends TypeAdapter<UserProfile> {
..writeByte(6)
..write(obj.lastPeriodStartDate)
..writeByte(7)
..write(obj.notificationsEnabled)
..write(obj.lastPadChangeTime)
..writeByte(8)
..write(obj.devotionalTime)
..write(obj.notificationsEnabled)
..writeByte(9)
..write(obj.hasCompletedOnboarding)
..writeByte(10)
@@ -104,7 +161,31 @@ class UserProfileAdapter extends TypeAdapter<UserProfile> {
..writeByte(25)
..write(obj.shareSleep)
..writeByte(26)
..write(obj.shareIntimacy);
..write(obj.shareIntimacy)
..writeByte(27)
..write(obj.isPadTrackingEnabled)
..writeByte(28)
..write(obj.typicalFlowIntensity)
..writeByte(29)
..write(obj.padBrand)
..writeByte(30)
..write(obj.padAbsorbency)
..writeByte(31)
..write(obj.padInventoryCount)
..writeByte(32)
..write(obj.lowInventoryThreshold)
..writeByte(33)
..write(obj.isAutoInventoryEnabled)
..writeByte(34)
..write(obj.lastInventoryUpdate)
..writeByte(38)
..write(obj.padSupplies)
..writeByte(35)
..write(obj.notifyPeriodEstimate)
..writeByte(36)
..write(obj.notifyPeriodStart)
..writeByte(37)
..write(obj.notifyLowSupply);
}
@override
@@ -314,6 +395,80 @@ class AppThemeModeAdapter extends TypeAdapter<AppThemeMode> {
typeId == other.typeId;
}
class PadTypeAdapter extends TypeAdapter<PadType> {
@override
final int typeId = 13;
@override
PadType read(BinaryReader reader) {
switch (reader.readByte()) {
case 0:
return PadType.pantyLiner;
case 1:
return PadType.regular;
case 2:
return PadType.super_pad;
case 3:
return PadType.overnight;
case 4:
return PadType.tampon_regular;
case 5:
return PadType.tampon_super;
case 6:
return PadType.menstrualCup;
case 7:
return PadType.menstrualDisc;
case 8:
return PadType.periodUnderwear;
default:
return PadType.pantyLiner;
}
}
@override
void write(BinaryWriter writer, PadType obj) {
switch (obj) {
case PadType.pantyLiner:
writer.writeByte(0);
break;
case PadType.regular:
writer.writeByte(1);
break;
case PadType.super_pad:
writer.writeByte(2);
break;
case PadType.overnight:
writer.writeByte(3);
break;
case PadType.tampon_regular:
writer.writeByte(4);
break;
case PadType.tampon_super:
writer.writeByte(5);
break;
case PadType.menstrualCup:
writer.writeByte(6);
break;
case PadType.menstrualDisc:
writer.writeByte(7);
break;
case PadType.periodUnderwear:
writer.writeByte(8);
break;
}
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PadTypeAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class UserRoleAdapter extends TypeAdapter<UserRole> {
@override
final int typeId = 8;