feat: 通知推送/免打扰偏好 + 饮食记录侧滑删除修复 + 聊天交互优化
- 通知: 新增推送开关/免打扰时段偏好持久化 + EF 迁移; 通知管线支持免打扰过滤 - 饮食: 侧滑删除 confirmDismiss 按方向放行(修复删不掉); 新增 diet_nutrition_widgets; 饮食录入页重构 - 聊天: 智能体胶囊点击锁防误触; 流式状态 select 优化; 卡片入场动画 - 主页: 消息列表提取 _HomeMessages + 侧滑手势打开抽屉 - 其他: api_client IP 适配; 通知/用药/饮食端点微调; 测试更新
This commit is contained in:
@@ -30,7 +30,6 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
final _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
double? _drawerDragStartX;
|
||||
String? _pickedImagePath;
|
||||
int _lastMsgCount = 0;
|
||||
Timer? _notificationTimer;
|
||||
|
||||
@override
|
||||
@@ -53,16 +52,6 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeMetrics() {
|
||||
// 键盘动画期间每帧都会回调,让列表底部始终贴住输入区上沿
|
||||
if (!_focusNode.hasFocus) return;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted || !_scrollCtrl.hasClients) return;
|
||||
_scrollCtrl.jumpTo(_scrollCtrl.position.maxScrollExtent);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
@@ -89,7 +78,6 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final chatState = ref.watch(chatProvider);
|
||||
final auth = ref.watch(authProvider);
|
||||
final user = auth.user;
|
||||
|
||||
@@ -112,15 +100,17 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
}
|
||||
});
|
||||
|
||||
final currentCount = chatState.messages.length;
|
||||
if (currentCount > _lastMsgCount) {
|
||||
ref.listen<int>(chatProvider.select((state) => state.messages.length), (
|
||||
previous,
|
||||
current,
|
||||
) {
|
||||
if (current <= (previous ?? 0)) return;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_scrollCtrl.hasClients) {
|
||||
if (mounted && _scrollCtrl.hasClients) {
|
||||
_scrollCtrl.jumpTo(_scrollCtrl.position.maxScrollExtent);
|
||||
}
|
||||
});
|
||||
}
|
||||
_lastMsgCount = currentCount;
|
||||
});
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
@@ -136,10 +126,7 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
child: Stack(
|
||||
children: [
|
||||
RepaintBoundary(
|
||||
child: ChatMessagesView(
|
||||
scrollCtrl: _scrollCtrl,
|
||||
messages: chatState.messages,
|
||||
),
|
||||
child: _HomeMessages(scrollCtrl: _scrollCtrl),
|
||||
),
|
||||
Positioned(
|
||||
left: 0,
|
||||
@@ -592,6 +579,18 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
}
|
||||
}
|
||||
|
||||
class _HomeMessages extends ConsumerWidget {
|
||||
final ScrollController scrollCtrl;
|
||||
|
||||
const _HomeMessages({required this.scrollCtrl});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final messages = ref.watch(chatProvider.select((state) => state.messages));
|
||||
return ChatMessagesView(scrollCtrl: scrollCtrl, messages: messages);
|
||||
}
|
||||
}
|
||||
|
||||
class _HeaderIconButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@@ -71,7 +71,9 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final chatState = ref.watch(chatProvider);
|
||||
final streaming = ref.watch(
|
||||
chatProvider.select((state) => (state.isStreaming, state.thinkingText)),
|
||||
);
|
||||
|
||||
if (messages.isEmpty) {
|
||||
return Center(
|
||||
@@ -107,10 +109,17 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
controller: scrollCtrl,
|
||||
reverse: false,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
cacheExtent: 180,
|
||||
itemCount: messages.length,
|
||||
itemBuilder: (context, index) {
|
||||
final msg = messages[index];
|
||||
return _buildMessageContent(context, ref, msg, chatState);
|
||||
return _buildMessageContent(
|
||||
context,
|
||||
ref,
|
||||
msg,
|
||||
streaming.$1,
|
||||
streaming.$2 ?? '',
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -121,7 +130,8 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
ChatMessage msg,
|
||||
ChatState chatState,
|
||||
bool isStreaming,
|
||||
String thinkingText,
|
||||
) {
|
||||
switch (msg.type) {
|
||||
case MessageType.agentWelcome:
|
||||
@@ -134,12 +144,10 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
case MessageType.dataConfirm:
|
||||
return _buildDataConfirmCard(context, ref, msg);
|
||||
default:
|
||||
if (!msg.isUser &&
|
||||
chatState.isStreaming &&
|
||||
msg.content.trim().isEmpty) {
|
||||
return _buildThinkingBubble(context, chatState.thinkingText);
|
||||
if (!msg.isUser && isStreaming && msg.content.trim().isEmpty) {
|
||||
return _buildThinkingBubble(context, thinkingText);
|
||||
}
|
||||
return _buildTextBubble(context, ref, msg, chatState);
|
||||
return _buildTextBubble(context, ref, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1048,7 +1056,6 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
ChatMessage msg,
|
||||
ChatState? chatState,
|
||||
) {
|
||||
final isUser = msg.isUser;
|
||||
final imageUrl = msg.metadata?['imageUrl'] as String?;
|
||||
@@ -1088,7 +1095,7 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: isUser ? AppTheme.primary : AppColors.cardBackground,
|
||||
color: isUser ? const Color(0xFF5F56FF) : AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(isUser ? 18.6 : 3),
|
||||
topRight: Radius.circular(isUser ? 3 : 18.6),
|
||||
|
||||
Reference in New Issue
Block a user