fix(mobile): hide negative age (#31341)
This commit is contained in:
+4
-2
@@ -106,6 +106,8 @@ class _Avatar extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final birthDate = person.birthDate;
|
||||
final formattedAge = birthDate != null ? formatAge(birthDate, assetFileCreatedAt) : null;
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 96),
|
||||
child: Padding(
|
||||
@@ -153,11 +155,11 @@ class _Avatar extends StatelessWidget {
|
||||
style: context.textTheme.labelLarge,
|
||||
maxLines: 1,
|
||||
),
|
||||
if (person.birthDate != null)
|
||||
if (formattedAge != null)
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
formatAge(person.birthDate!, assetFileCreatedAt),
|
||||
formattedAge,
|
||||
textAlign: TextAlign.center,
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: context.textTheme.bodyMedium?.color?.withAlpha(175),
|
||||
|
||||
@@ -4,10 +4,14 @@ import 'package:immich_mobile/generated/translations.g.dart';
|
||||
import 'package:immich_mobile/presentation/widgets/people/person_edit_birthday_modal.widget.dart';
|
||||
import 'package:immich_mobile/presentation/widgets/people/person_edit_name_modal.widget.dart';
|
||||
|
||||
String formatAge(DateTime birthDate, DateTime referenceDate) {
|
||||
String? formatAge(DateTime birthDate, DateTime referenceDate) {
|
||||
final int ageInYears = _calculateAge(birthDate, referenceDate);
|
||||
final int ageInMonths = _calculateAgeInMonths(birthDate, referenceDate);
|
||||
|
||||
if (ageInYears < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final t = StaticTranslations.instance;
|
||||
if (ageInMonths <= 11) {
|
||||
return t.person_age_months(months: ageInMonths);
|
||||
|
||||
Reference in New Issue
Block a user