1
This commit is contained in:
@@ -1,35 +1,53 @@
|
||||
/// 格式化日期时间
|
||||
String formatDateUS(dynamic date, [String format = 'MM/DD/YYYY hh:mm:ss a']) {
|
||||
DateTime dateTime;
|
||||
|
||||
if (date is String) {
|
||||
dateTime = DateTime.tryParse(date) ?? DateTime.now();
|
||||
} else if (date is DateTime) {
|
||||
dateTime = date;
|
||||
|
||||
// /// 格式化日期时间
|
||||
// String formatDateUS(dynamic date, [String format = 'MM/DD/YYYY hh:mm:ss a']) {
|
||||
// DateTime dateTime;
|
||||
//
|
||||
// if (date is String) {
|
||||
// dateTime = DateTime.tryParse(date) ?? DateTime.now();
|
||||
// } else if (date is DateTime) {
|
||||
// dateTime = date;
|
||||
// } else {
|
||||
// dateTime = DateTime.now();
|
||||
// }
|
||||
//
|
||||
// final yyyy = dateTime.year.toString();
|
||||
// final MM = dateTime.month.toString().padLeft(2, '0');
|
||||
// final dd = dateTime.day.toString().padLeft(2, '0');
|
||||
//
|
||||
// // 12小时制
|
||||
// final hour12 = (dateTime.hour % 12 == 0 ? 12 : dateTime.hour % 12).toString().padLeft(2, '0');
|
||||
// final HH = dateTime.hour.toString().padLeft(2, '0'); // 24小时制备用
|
||||
// final mm = dateTime.minute.toString().padLeft(2, '0');
|
||||
// final ss = dateTime.second.toString().padLeft(2, '0');
|
||||
// final ampm = dateTime.hour >= 12 ? 'PM' : 'AM';
|
||||
//
|
||||
// String result = format
|
||||
// .replaceFirst(RegExp('YYYY'), yyyy)
|
||||
// .replaceFirst(RegExp('MM'), MM)
|
||||
// .replaceFirst(RegExp('DD'), dd)
|
||||
// .replaceFirst(RegExp('hh'), hour12)
|
||||
// .replaceFirst(RegExp('HH'), HH)
|
||||
// .replaceFirst(RegExp('mm'), mm)
|
||||
// .replaceFirst(RegExp('ss'), ss)
|
||||
// .replaceFirst(RegExp('a'), ampm);
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String formatDateUS(String dateStr, {bool withTime = false}) {
|
||||
// 假设后端返回的格式是 "2025-09-05T15:25:00Z"
|
||||
final date = DateTime.parse(dateStr);
|
||||
|
||||
if (withTime) {
|
||||
return DateFormat("MMM d, yyyy 'at' h:mm a", 'en_US').format(date.toLocal());
|
||||
// 输出: Sep 5, 2025 at 11:25 PM (取本地时区)
|
||||
} else {
|
||||
dateTime = DateTime.now();
|
||||
return DateFormat("MMM d, yyyy", 'en_US').format(date.toLocal());
|
||||
// 输出: Sep 5, 2025
|
||||
}
|
||||
|
||||
final yyyy = dateTime.year.toString();
|
||||
final MM = dateTime.month.toString().padLeft(2, '0');
|
||||
final dd = dateTime.day.toString().padLeft(2, '0');
|
||||
|
||||
// 12小时制
|
||||
final hour12 = (dateTime.hour % 12 == 0 ? 12 : dateTime.hour % 12).toString().padLeft(2, '0');
|
||||
final HH = dateTime.hour.toString().padLeft(2, '0'); // 24小时制备用
|
||||
final mm = dateTime.minute.toString().padLeft(2, '0');
|
||||
final ss = dateTime.second.toString().padLeft(2, '0');
|
||||
final ampm = dateTime.hour >= 12 ? 'PM' : 'AM';
|
||||
|
||||
String result = format
|
||||
.replaceFirst(RegExp('YYYY'), yyyy)
|
||||
.replaceFirst(RegExp('MM'), MM)
|
||||
.replaceFirst(RegExp('DD'), dd)
|
||||
.replaceFirst(RegExp('hh'), hour12)
|
||||
.replaceFirst(RegExp('HH'), HH)
|
||||
.replaceFirst(RegExp('mm'), mm)
|
||||
.replaceFirst(RegExp('ss'), ss)
|
||||
.replaceFirst(RegExp('a'), ampm);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class StreamUtils {
|
||||
}
|
||||
//数据
|
||||
var bufferText = ""; //吐出来的内容
|
||||
|
||||
final completer = Completer<void>();
|
||||
//处理响应
|
||||
response.data?.stream
|
||||
.transform(_unit8Transformer())
|
||||
@@ -63,6 +63,9 @@ class StreamUtils {
|
||||
}
|
||||
Map<String, dynamic> dataJSON = jsonDecode(streamStr);
|
||||
//提取响应数据
|
||||
if (dataJSON['choices'].length == 0) {
|
||||
continue;
|
||||
}
|
||||
Map<String, dynamic> choices = dataJSON['choices'][0];
|
||||
//提取文字
|
||||
var word = choices['delta']['content'];
|
||||
@@ -80,12 +83,17 @@ class StreamUtils {
|
||||
},
|
||||
onDone: () {
|
||||
onEnd?.call();
|
||||
completer.complete();
|
||||
},
|
||||
onError: (error) {
|
||||
onError?.call();
|
||||
logger.e("流错误: $error");
|
||||
if (!completer.isCompleted) {
|
||||
completer.completeError(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
/// 将Uint8List转换为List<int>
|
||||
|
||||
Reference in New Issue
Block a user