Files
AI-Health/health_app/lib/widgets/agent_bar.dart
MingNian 8dcf99cac5 style: 全项目紫色→薄荷绿 Fresh Air 清新风
- 主色 #635BFF→#14B8A6 (薄荷绿)
- 浅紫 #EDEBFF→#E6FAF6 (极浅薄荷)
- 深紫 #4B44D6→#0F9D8E (深薄荷)
- 渐变紫→薄荷渐变
- 全局13种紫色映射替换
2026-06-03 20:30:28 +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(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))),
],
),
),
);
}
}