import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:get/get_core/src/get_main.dart'; import 'package:location/resource/assets.gen.dart'; import '../data/consts/payment_type.dart'; /// 截取后几位 String stringExpand(String phone) { if (phone.length < 4) { return phone; } return phone.substring(phone.length - 4); } ///截取前几位 String stringShort(String phone) { if (phone.length < 4) { return phone; } return phone.substring(0, 4); } String userNickName(String? remark, String phoneNumber, bool isIntercept) { if (remark != null && remark.isNotEmpty) { return isIntercept ? stringShort(remark) : remark; } else { return isIntercept ? stringExpand(phoneNumber) : phoneNumber; } } String time2TimeDesc(int? timeMillis) { if (timeMillis == 0 || timeMillis == null) { return "未知"; } int currentTimeMillis = DateTime.now().millisecondsSinceEpoch; int timeDiff = currentTimeMillis - timeMillis; if (timeDiff < 0) { return "刚刚"; } int minute = timeDiff ~/ 60 ~/ 1000; if (minute < 60) { if (minute == 0) { return "刚刚"; } return "$minute分钟前"; } int hour = minute ~/ 60; if (hour < 24) { return "$hour小时前"; } int day = hour ~/ 24; if (day < 30) { return "$day天前"; } int month = day ~/ 30; if (month < 12) { return "$month月前"; } int year = month ~/ 12; return "$year年前"; } String addressCheck(String? address) { if (address == null || address.isEmpty) { return "未开启定位"; } return address; } void copyToClipboard(String content) { Clipboard.setData(ClipboardData(text: content)); } void backToSpecificPage(String targetRoute) { Get.until((route) => Get.currentRoute == targetRoute); }