import 'dart:convert'; // DateFormat('dd.MM.yy HH:mm:ss').format(dateCreated); // ?? String formatTimeStamp({int? timeStamp, DateTime? date, format='yyyy-MM-dd HH:mm:ss'}) { try { var time = (date != null) ? date : ((timeStamp != null) ? DateTime.fromMillisecondsSinceEpoch(timeStamp) : DateTime.now()); var dateObj = { 'M+': time.month, //月份 'd+': time.day, //日 'H+': time.hour, //小时 'm+': time.minute, //分 's+': time.second, //秒 }; RegExp yearReg = RegExp(r"(y+)"); if (yearReg.hasMatch(format)) { var matches = yearReg.allMatches(format); String match = "${matches.elementAt(0).group(1)}"; format = format.replaceAll(match, "${time.year}".substring(4 - match.length)); } dateObj.forEach((key, value) { RegExp replaceReg = RegExp(r'(' + key + ')'); if (replaceReg.hasMatch(format)) { var matches = replaceReg.allMatches(format); String match = "${matches.elementAt(0).group(1)}"; format = format.replaceAll(match, (match.length == 1) ? "$value" : "00$value".substring("$value".length)); } }); return format; } catch (error) { return ''; } } void printJsonStr(String input) { const JsonDecoder decoder = JsonDecoder(); const JsonEncoder encoder = JsonEncoder.withIndent(' '); final dynamic object = decoder.convert(input); final dynamic prettyString = encoder.convert(object); prettyString.split('\n').forEach((dynamic element) => print(element)); } void printJson(Map input) { const JsonEncoder encoder = JsonEncoder.withIndent(' '); final dynamic prettyString = encoder.convert(input); prettyString.split('\n').forEach((dynamic element) => print(element)); } // move to fileUtils.dart // String formatFileSize(int size) { // final fileSizeInKB = size / 1000; // if (fileSizeInKB < 1) { // return '$size bytes'; // } // final fileSizeInMB = fileSizeInKB / 1000; // if (fileSizeInMB < 1) { // return '${fileSizeInKB.toStringAsFixed(2)} KB'; // } // final fileSizeInGB = fileSizeInMB / 1000; // if (fileSizeInGB < 1) { // return '${fileSizeInMB.toStringAsFixed(2)} MB'; // } // final fileSizeInTB = fileSizeInGB / 1000; // if (fileSizeInTB < 1) { // return '${fileSizeInGB.toStringAsFixed(2)} GB'; // } // return '${fileSizeInTB.toStringAsFixed(2)} TB'; // } // 均匀分组 List uniformGrouping(int totalSize, int defaultGroupSize) { if (totalSize < 0) { return []; } else if (totalSize == 0) { return [0]; } final int theUpperLimit = (defaultGroupSize * 1.5).toInt(); // 折行上限 if (totalSize <= theUpperLimit) { return [totalSize]; } else if ((totalSize > theUpperLimit) && (totalSize <= (defaultGroupSize * 2))) { int half = totalSize ~/ 2; return [half, totalSize - half]; } final int groupNumber = totalSize ~/ defaultGroupSize; final int remainder = totalSize % defaultGroupSize; List group = []; if (remainder == 0) { for (int i = 0; i < groupNumber; i++) { group.add(defaultGroupSize); } } else { final splitRemainder = remainder ~/ groupNumber; final groupRemainder = remainder % groupNumber; for (int i = 0; i < groupRemainder; i++) { group.add(defaultGroupSize + splitRemainder + 1); } for (int i = groupRemainder; i < groupNumber; i++) { group.add((defaultGroupSize + splitRemainder)); } } return group; }