import 'dart:math'; import 'package:crypto/crypto.dart'; import 'dart:convert'; class CommonUtil { static String generateMd5(String input) { List bytes = utf8.encode(input); // 将字符串转换为字节码 Digest md5Hash = md5.convert(bytes); // 对字节码进行MD5加密 String encryptedString = md5Hash.toString(); // 获取加密后的字符串 return encryptedString; } static String generateTicketNumber() { Random random = Random(); int randomTwoDigitNumber = random.nextInt(99); String twoDigitNumber = randomTwoDigitNumber.toString().padLeft(2, '0'); // 格式化数字串 String formattedNumber = '${random.nextInt(9999999).toString().padLeft(7, '0')}${random.nextInt(9999999).toString().padLeft(7, '0')}-$twoDigitNumber'; return formattedNumber; } static String firstUppercase(String text) { return '${text[0].toUpperCase()}${text.substring(1)}'; } static List flattenTree(List children) { List result = children; for (T child in children) { if (child.children != null) { result.addAll(flattenTree(child.children as List)); } } return result; } static String toNumberWithout0(num num) { return num.toStringAsFixed(num.truncateToDouble() == num ? 0 : 2); } } class TreeNode { List? children; }