fixed time ago in notifications
This commit is contained in:
@@ -315,17 +315,18 @@ class NotificationViewModel with ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
String timeAgo(String dateTimeString) {
|
String timeAgo(timestamp) {
|
||||||
final createdAt = DateTime.parse(dateTimeString);
|
final int ts = int.tryParse(timestamp.toString()) ?? 0;
|
||||||
|
final createdAt = DateTime.fromMillisecondsSinceEpoch(ts * 1000).toLocal();
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final difference = now.difference(createdAt);
|
final difference = now.difference(createdAt);
|
||||||
|
|
||||||
if (difference.inMinutes < 1) {
|
if (difference.inMinutes < 1) {
|
||||||
return NotificationStrings.now;
|
return NotificationStrings.now;
|
||||||
} else if (difference.inMinutes < 60) {
|
} else if (difference.inMinutes < 60) {
|
||||||
return '${difference.inMinutes} ${NotificationStrings.min} ';
|
return '${difference.inMinutes} ${NotificationStrings.min}';
|
||||||
} else if (difference.inHours < 24) {
|
} else if (difference.inHours < 24) {
|
||||||
return '${difference.inHours} ${NotificationStrings.hour} ';
|
return '${difference.inHours} ${NotificationStrings.hour}';
|
||||||
} else if (difference.inDays == 1) {
|
} else if (difference.inDays == 1) {
|
||||||
return NotificationStrings.yesterday;
|
return NotificationStrings.yesterday;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class NotificationCard extends StatelessWidget {
|
|||||||
SvgPicture.asset(AssetsManager.calendar),
|
SvgPicture.asset(AssetsManager.calendar),
|
||||||
SizedBox(width: 4.0.w()),
|
SizedBox(width: 4.0.w()),
|
||||||
Text(
|
Text(
|
||||||
viewModel.timeAgo(notification.createdAt!),
|
viewModel.timeAgo(notification.createdAt!.toString()),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12.0.sp(),
|
fontSize: 12.0.sp(),
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
|
|||||||
Reference in New Issue
Block a user