common_util.dart 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import 'package:flutter/services.dart';
  2. import 'package:location/resource/assets.gen.dart';
  3. import '../data/consts/payment_type.dart';
  4. /// 截取后几位
  5. String stringExpand(String phone) {
  6. if (phone.length < 4) {
  7. return phone;
  8. }
  9. return phone.substring(phone.length - 4);
  10. }
  11. ///截取前几位
  12. String stringShort(String phone) {
  13. if (phone.length < 4) {
  14. return phone;
  15. }
  16. return phone.substring(0, 4);
  17. }
  18. String userNickName(String? remark, String phoneNumber, bool isIntercept) {
  19. if (remark != null && remark.isNotEmpty) {
  20. return isIntercept ? stringShort(remark) : remark;
  21. } else {
  22. return isIntercept ? stringExpand(phoneNumber) : phoneNumber;
  23. }
  24. }
  25. String time2TimeDesc(int? timeMillis) {
  26. if (timeMillis == 0 || timeMillis == null) {
  27. return "未知";
  28. }
  29. int currentTimeMillis = DateTime.now().millisecondsSinceEpoch;
  30. int timeDiff = currentTimeMillis - timeMillis;
  31. if (timeDiff < 0) {
  32. return "刚刚";
  33. }
  34. int minute = timeDiff ~/ 60 ~/ 1000;
  35. if (minute < 60) {
  36. if (minute == 0) {
  37. return "刚刚";
  38. }
  39. return "$minute分钟前";
  40. }
  41. int hour = minute ~/ 60;
  42. if (hour < 24) {
  43. return "$hour小时前";
  44. }
  45. int day = hour ~/ 24;
  46. if (day < 30) {
  47. return "$day天前";
  48. }
  49. int month = day ~/ 30;
  50. if (month < 12) {
  51. return "$month月前";
  52. }
  53. int year = month ~/ 12;
  54. return "$year年前";
  55. }
  56. String addressCheck(String? address) {
  57. if (address == null || address.isEmpty) {
  58. return "未开启定位";
  59. }
  60. return address;
  61. }
  62. void copyToClipboard(String content) {
  63. Clipboard.setData(ClipboardData(text: content));
  64. }