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(0xFF14B8A6) : Colors.white, border: Border.all(color: const Color(0xFF14B8A6)), borderRadius: BorderRadius.circular(24), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(icon, size: 16, color: isSelected ? Colors.white : const Color(0xFF14B8A6)), const SizedBox(width: 6), Text(label, style: TextStyle(fontSize: 13, color: isSelected ? Colors.white : const Color(0xFF14B8A6))), ], ), ), ); } }