ext_community.dart 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import 'package:eye_video/bizmodule/main/community/model/community_model.dart';
  2. const int _MINUTE = 60; // 1分钟
  3. const int _HOUR = 60 * _MINUTE; // 1小时
  4. const int _DAY = 24 * _HOUR; // 1天
  5. const int _MONTH = 31 * _DAY; // 月
  6. const int _YEAR = 12 * _MONTH; // 年
  7. String prettyTime(int timeMillis) {
  8. if (timeMillis < 0) return "";
  9. var currentMills = DateTime.now().millisecondsSinceEpoch;
  10. int seconds = (currentMills - timeMillis) ~/ 1000;
  11. if (seconds <= 0) {
  12. return "刚刚";
  13. }
  14. if (seconds < 60) {
  15. return "${seconds.toString()}秒前";
  16. }
  17. int minutes = seconds ~/ _MINUTE;
  18. if (seconds < 60) {
  19. return "${minutes.toString()}分钟前";
  20. }
  21. int hours = seconds ~/ _HOUR;
  22. if (hours < 24) {
  23. return "${hours.toString()}小时前";
  24. }
  25. int days = seconds ~/ _DAY;
  26. if (days < 31) {
  27. return "${days.toString()}天前";
  28. }
  29. int months = seconds ~/ _MONTH;
  30. if (months < 12) {
  31. return "${months.toString()}月前";
  32. }
  33. int years = seconds ~/ _YEAR;
  34. return "${years.toString()}年前";
  35. }
  36. extension ExtCommunity on Community {
  37. bool get isHorizontalScrollCard =>
  38. this.type == 'horizontalScrollCard' &&
  39. data != null &&
  40. data.dataType == 'HorizontalScrollCard' &&
  41. data.communityList.isNotEmpty;
  42. bool get isPicFollowCard =>
  43. this.type == 'pictureFollowCard' &&
  44. data != null &&
  45. data.dataType == 'FollowCard' &&
  46. data.header != null &&
  47. data.content != null;
  48. }