mirror of
https://github.com/Dvorinka/1356.git
synced 2026-06-05 04:22:55 +00:00
small fix, don't worry about it
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../core/utils/unit_conversion_utils.dart';
|
||||
|
||||
class User extends Equatable {
|
||||
final String id;
|
||||
@@ -13,6 +14,13 @@ class User extends Equatable {
|
||||
final String? websiteUrl;
|
||||
final DateTime? countdownStartDate;
|
||||
final DateTime? countdownEndDate;
|
||||
final Gender? gender;
|
||||
final DateTime? birthDate;
|
||||
final int? storedAge;
|
||||
final double? heightCm;
|
||||
final double? weightKg;
|
||||
final HeightUnit heightUnit;
|
||||
final WeightUnit weightUnit;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
|
||||
@@ -29,6 +37,13 @@ class User extends Equatable {
|
||||
this.websiteUrl,
|
||||
this.countdownStartDate,
|
||||
this.countdownEndDate,
|
||||
this.gender,
|
||||
this.birthDate,
|
||||
this.storedAge,
|
||||
this.heightCm,
|
||||
this.weightKg,
|
||||
this.heightUnit = HeightUnit.metric,
|
||||
this.weightUnit = WeightUnit.metric,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
});
|
||||
@@ -45,6 +60,33 @@ class User extends Equatable {
|
||||
return countdownEndDate!.difference(DateTime.now()).inDays;
|
||||
}
|
||||
|
||||
int? get age {
|
||||
if (storedAge != null) return storedAge;
|
||||
if (birthDate == null) return null;
|
||||
return UnitConversionUtils.calculateAge(birthDate!);
|
||||
}
|
||||
|
||||
String get formattedHeight {
|
||||
if (heightCm == null) return '';
|
||||
return UnitConversionUtils.formatHeight(heightCm!, heightUnit);
|
||||
}
|
||||
|
||||
String get formattedWeight {
|
||||
if (weightKg == null) return '';
|
||||
return UnitConversionUtils.formatWeight(weightKg!, weightUnit);
|
||||
}
|
||||
|
||||
double? get bmi {
|
||||
if (heightCm == null || weightKg == null) return null;
|
||||
return UnitConversionUtils.calculateBmi(weightKg!, heightCm!);
|
||||
}
|
||||
|
||||
String get bmiCategory {
|
||||
final bmiValue = bmi;
|
||||
if (bmiValue == null) return '';
|
||||
return UnitConversionUtils.getBmiCategory(bmiValue);
|
||||
}
|
||||
|
||||
User copyWith({
|
||||
String? id,
|
||||
String? username,
|
||||
@@ -58,6 +100,13 @@ class User extends Equatable {
|
||||
String? websiteUrl,
|
||||
DateTime? countdownStartDate,
|
||||
DateTime? countdownEndDate,
|
||||
Gender? gender,
|
||||
DateTime? birthDate,
|
||||
int? storedAge,
|
||||
double? heightCm,
|
||||
double? weightKg,
|
||||
HeightUnit? heightUnit,
|
||||
WeightUnit? weightUnit,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
@@ -74,6 +123,13 @@ class User extends Equatable {
|
||||
websiteUrl: websiteUrl ?? this.websiteUrl,
|
||||
countdownStartDate: countdownStartDate ?? this.countdownStartDate,
|
||||
countdownEndDate: countdownEndDate ?? this.countdownEndDate,
|
||||
gender: gender ?? this.gender,
|
||||
birthDate: birthDate ?? this.birthDate,
|
||||
storedAge: storedAge ?? this.storedAge,
|
||||
heightCm: heightCm ?? this.heightCm,
|
||||
weightKg: weightKg ?? this.weightKg,
|
||||
heightUnit: heightUnit ?? this.heightUnit,
|
||||
weightUnit: weightUnit ?? this.weightUnit,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
@@ -93,6 +149,13 @@ class User extends Equatable {
|
||||
websiteUrl,
|
||||
countdownStartDate,
|
||||
countdownEndDate,
|
||||
gender,
|
||||
birthDate,
|
||||
storedAge,
|
||||
heightCm,
|
||||
weightKg,
|
||||
heightUnit,
|
||||
weightUnit,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
];
|
||||
@@ -111,6 +174,13 @@ class User extends Equatable {
|
||||
'website_url': websiteUrl,
|
||||
'countdown_start_date': countdownStartDate?.toIso8601String(),
|
||||
'countdown_end_date': countdownEndDate?.toIso8601String(),
|
||||
'gender': gender?.toDatabaseString(),
|
||||
'birth_date': birthDate?.toIso8601String().split('T').first,
|
||||
'age': storedAge,
|
||||
'height_cm': heightCm,
|
||||
'weight_kg': weightKg,
|
||||
'height_unit': heightUnit.code,
|
||||
'weight_unit': weightUnit.code,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'updated_at': updatedAt.toIso8601String(),
|
||||
};
|
||||
@@ -134,6 +204,15 @@ class User extends Equatable {
|
||||
countdownEndDate: json['countdown_end_date'] != null
|
||||
? DateTime.parse(json['countdown_end_date'] as String)
|
||||
: null,
|
||||
gender: json['gender'] != null ? Gender.fromString(json['gender'] as String) : null,
|
||||
birthDate: json['birth_date'] != null ? DateTime.parse(json['birth_date'] as String) : null,
|
||||
storedAge: json['age'] as int?,
|
||||
heightCm: json['height_cm'] as double?,
|
||||
weightKg: json['weight_kg'] as double?,
|
||||
heightUnit: json['height_unit'] != null ?
|
||||
HeightUnit.values.firstWhere((unit) => unit.code == json['height_unit']) : HeightUnit.metric,
|
||||
weightUnit: json['weight_unit'] != null ?
|
||||
WeightUnit.values.firstWhere((unit) => unit.code == json['weight_unit']) : WeightUnit.metric,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user