Код: Выделить всё
child: CupertinoDatePicker(
maximumDate: DateTime.now(),
initialDateTime: selectedDate,
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (DateTime dateTime) {
setState(() {
selectedDate = dateTime;
_calculateAge(dateTime);
log('Selected date: ${dateTime.toIso8601String()}');
final utcString = dateTime.toUtc().toIso8601String();
widget.onInfoUpdated(
(widget.userProfileData ?? UserProfileData()).copyWith(
ageText: age.toString(),
dateOfBirth: utcString,
),
);
});
},
),
),
Код: Выделить всё
class UserProfileData {
final String? ageText;
final String? dateOfBirth;
UserProfileData({this.ageText, this.dateOfBirth});
UserProfileData copyWith({
String? ageText,
String? dateOfBirth,
}) {
return UserProfileData(
ageText: ageText ?? this.ageText,
dateOfBirth: dateOfBirth ?? this.dateOfBirth,
);
}
}
< /code>
Это тот класс, который вы ищете. Если бы я поместил два журнала для Agetextext и DateOfbirth одновременно, я бы по какой-то причине получил NULL в текст DateOfbirth.log('Updated age=$age, dob=$utcString');
Подробнее здесь: https://stackoverflow.com/questions/796 ... ng-a-field
Мобильная версия