Files
AI-Health/health_app/lib/widgets/agent_bar.dart
MingNian f6c1ea7ec9 style: 淡薰紫 Lavender Breeze + UI修复
- 主色改淡薰紫 #8B9CF7 + 白底 清新风格
- 每个智能体卡不同淡色调
- 删除欢迎卡底部"或直接对我说"
- 运动创建/打卡接入 API
- 全项目薄荷绿→淡紫替换
2026-06-03 20:46:39 +08:00

62 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/chat_provider.dart';
/// 智能体胶囊栏——横向滑动
class AgentBar extends ConsumerWidget {
const AgentBar({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final selected = ref.watch(selectedAgentProvider);
final chatNotifier = ref.read(chatProvider.notifier);
void onTap(ActiveAgent agent) {
final notifier = ref.read(selectedAgentProvider.notifier);
notifier.select(agent == selected ? null : agent);
chatNotifier.setAgent(agent);
}
return Container(
height: 48,
color: Colors.white,
child: ListView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 12),
children: [
_buildCapsule('AI问诊', Icons.medical_services, ActiveAgent.consultation, selected, onTap),
_buildCapsule('记数据', Icons.edit_note, ActiveAgent.health, selected, onTap),
_buildCapsule('拍饮食', Icons.restaurant, ActiveAgent.diet, selected, onTap),
_buildCapsule('药管家', Icons.medication, ActiveAgent.medication, selected, onTap),
_buildCapsule('看报告', Icons.description, ActiveAgent.report, selected, onTap),
_buildCapsule('运动计划', Icons.fitness_center, ActiveAgent.exercise, selected, onTap),
],
),
);
}
Widget _buildCapsule(String label, IconData icon, ActiveAgent agent, ActiveAgent? selected, void Function(ActiveAgent) onTap) {
final isSelected = selected == agent;
return GestureDetector(
onTap: () => onTap(agent),
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 6),
padding: const EdgeInsets.symmetric(horizontal: 14),
decoration: BoxDecoration(
color: isSelected ? const Color(0xFF8B9CF7) : Colors.white,
border: Border.all(color: const Color(0xFF8B9CF7)),
borderRadius: BorderRadius.circular(24),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, size: 16, color: isSelected ? Colors.white : const Color(0xFF8B9CF7)),
const SizedBox(width: 6),
Text(label, style: TextStyle(fontSize: 13, color: isSelected ? Colors.white : const Color(0xFF8B9CF7))),
],
),
),
);
}
}