feat:增加消息记录功能
This commit is contained in:
26
lib/utils/date_utils.dart
Normal file
26
lib/utils/date_utils.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String formatChatTime(DateTime time) {
|
||||
final now = DateTime.now();
|
||||
final t = time.toLocal();
|
||||
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final d = DateTime(t.year, t.month, t.day);
|
||||
|
||||
final diff = today.difference(d).inDays;
|
||||
final hm = DateFormat('HH:mm').format(t);
|
||||
|
||||
if (diff == 0) return hm;
|
||||
if (diff == 1) return '昨天 $hm';
|
||||
|
||||
// 本周
|
||||
if (diff < 7 && d.weekday <= now.weekday) {
|
||||
return '${DateFormat('EEEEE', 'zh_CN').format(t)} $hm';
|
||||
}
|
||||
|
||||
if (t.year == now.year) {
|
||||
return DateFormat('M月d日 HH:mm').format(t);
|
||||
}
|
||||
|
||||
return DateFormat('yyyy年M月d日 HH:mm').format(t);
|
||||
}
|
||||
37
lib/utils/toast_utils.dart
Normal file
37
lib/utils/toast_utils.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
class ToastUtils {
|
||||
static void _show({
|
||||
required String msg,
|
||||
Color backgroundColor = Colors.black87,
|
||||
Color textColor = Colors.white,
|
||||
ToastGravity gravity = ToastGravity.CENTER,
|
||||
Toast toastLength = Toast.LENGTH_SHORT,
|
||||
}) {
|
||||
Fluttertoast.showToast(
|
||||
msg: msg,
|
||||
toastLength: toastLength,
|
||||
gravity: gravity,
|
||||
backgroundColor: backgroundColor,
|
||||
textColor: textColor,
|
||||
fontSize: 14.0,
|
||||
);
|
||||
}
|
||||
|
||||
static void success(String msg) {
|
||||
_show(msg: msg, backgroundColor: Colors.green);
|
||||
}
|
||||
|
||||
static void error(String msg) {
|
||||
_show(msg: msg, backgroundColor: Colors.redAccent);
|
||||
}
|
||||
|
||||
static void warning(String msg) {
|
||||
_show(msg: msg, backgroundColor: Colors.orange);
|
||||
}
|
||||
|
||||
static void info(String msg) {
|
||||
_show(msg: msg, backgroundColor: Colors.grey[800]!);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user