Compare commits
21 Commits
c6395ea9b4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bd0155e17 | ||
|
|
f6c1ea7ec9 | ||
|
|
f46c30f8e7 | ||
|
|
8dcf99cac5 | ||
|
|
f484c6b66a | ||
|
|
7cd79bce68 | ||
|
|
2cb1cf4a9c | ||
|
|
ff96fb6c4c | ||
|
|
ea7226c805 | ||
|
|
15f9a122ca | ||
|
|
e3b9716f7c | ||
|
|
95bf5732f6 | ||
|
|
711b583aaf | ||
|
|
7953cca15d | ||
|
|
07ddf2577a | ||
|
|
0e49b9a952 | ||
|
|
ed716654b3 | ||
|
|
9fb60cb3cf | ||
|
|
36ad334643 | ||
|
|
7b898f8660 | ||
|
|
78573eaa5f |
@@ -124,6 +124,7 @@ public sealed class VisionClient(HttpClient http, IConfiguration config)
|
||||
var request = new ChatCompletionRequest
|
||||
{
|
||||
Model = _model, Messages = messages, MaxTokens = maxTokens, Stream = false,
|
||||
Temperature = 0.7f, TopP = 0.8f,
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(request, _jsonOptions);
|
||||
|
||||
@@ -164,6 +164,7 @@ public sealed class ChatCompletionRequest
|
||||
public bool Stream { get; set; }
|
||||
public int MaxTokens { get; set; } = 2048;
|
||||
public float Temperature { get; set; } = 0.7f;
|
||||
public float? TopP { get; set; }
|
||||
public List<ToolDefinition>? Tools { get; set; }
|
||||
public string? ToolChoice { get; set; }
|
||||
}
|
||||
|
||||
@@ -267,22 +267,17 @@ public static class AiChatEndpoints
|
||||
|
||||
// 压缩图片后转 base64(VLM API 有请求体大小限制)
|
||||
var compressedPath = Path.Combine(uploadsDir, $"compressed_{safeName}");
|
||||
CompressImage(filePath, compressedPath, maxWidth: 2048, quality: 92L);
|
||||
CompressImage(filePath, compressedPath, maxWidth: 1280, quality: 75L);
|
||||
var compressedBytes = await File.ReadAllBytesAsync(compressedPath, ct);
|
||||
var base64 = Convert.ToBase64String(compressedBytes);
|
||||
imageUrls.Add($"data:image/jpeg;base64,{base64}");
|
||||
}
|
||||
|
||||
var prompt = """
|
||||
识别图片中所有食物,用中文名称,只返回JSON:
|
||||
{
|
||||
"foods": [{"name":"食物名","portion":"份量","calories":整数}]
|
||||
}
|
||||
""";
|
||||
var prompt = "精准识别用户提供的食物图片,提取并返回详细信息,包括但不限于食物名称、具体份量及对应热量值。系统应确保识别结果的准确性和清晰度,以便为病人的饮食管理提供可靠数据支持。";
|
||||
|
||||
try
|
||||
{
|
||||
var response = await visionClient.VisionAsync(prompt, imageUrls, ct: ct);
|
||||
var response = await visionClient.VisionAsync(prompt, imageUrls, userText: "请看图识别食物", ct: ct);
|
||||
var result = response.Choices?.FirstOrDefault()?.Message?.Content ?? "{}";
|
||||
return Results.Ok(new { code = 0, data = result, message = (string?)null });
|
||||
}
|
||||
|
||||
@@ -101,6 +101,31 @@ public static class RemainingEndpoints
|
||||
await db.SaveChangesAsync(ct);
|
||||
return Results.Ok(new { code = 0, data = new { success = true }, message = (string?)null });
|
||||
});
|
||||
|
||||
// 获取待提醒的用药
|
||||
group.MapGet("/reminders", async (HttpContext http, AppDbContext db, CancellationToken ct) =>
|
||||
{
|
||||
var userId = GetUserId(http);
|
||||
var now = TimeOnly.FromDateTime(DateTime.Now);
|
||||
var windowEnd = now.AddHours(1);
|
||||
var meds = await db.Medications
|
||||
.Where(m => m.UserId == userId && m.IsActive && m.TimeOfDay != null)
|
||||
.ToListAsync(ct);
|
||||
var due = meds.Where(m => m.TimeOfDay!.Any(t => t >= now && t <= windowEnd)).ToList();
|
||||
|
||||
// 检查今天是否已打卡
|
||||
var today = DateOnly.FromDateTime(DateTime.Now);
|
||||
var dueMeds = new List<object>();
|
||||
foreach (var m in due)
|
||||
{
|
||||
var logged = await db.MedicationLogs.AnyAsync(l =>
|
||||
l.MedicationId == m.Id && l.CreatedAt >= today.ToDateTime(TimeOnly.MinValue) && l.Status == MedicationLogStatus.Taken, ct);
|
||||
if (!logged)
|
||||
dueMeds.Add(new { m.Id, m.Name, m.Dosage, m.TimeOfDay });
|
||||
}
|
||||
|
||||
return Results.Ok(new { code = 0, data = dueMeds, message = (string?)null });
|
||||
});
|
||||
}
|
||||
|
||||
public static void MapReportEndpoints(this WebApplication app)
|
||||
|
||||
|
After Width: | Height: | Size: 602 KiB |
|
After Width: | Height: | Size: 602 KiB |
|
Before Width: | Height: | Size: 5.2 MiB After Width: | Height: | Size: 5.2 MiB |
|
After Width: | Height: | Size: 602 KiB |
|
After Width: | Height: | Size: 602 KiB |
|
After Width: | Height: | Size: 5.2 MiB |
|
After Width: | Height: | Size: 602 KiB |
|
After Width: | Height: | Size: 5.2 MiB |
|
After Width: | Height: | Size: 602 KiB |
|
After Width: | Height: | Size: 602 KiB |
|
After Width: | Height: | Size: 602 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 231 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 339 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 914 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 257 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 602 KiB |
|
After Width: | Height: | Size: 602 KiB |
|
After Width: | Height: | Size: 5.2 MiB |
|
After Width: | Height: | Size: 602 KiB |
@@ -36,8 +36,7 @@ public class AiAgentTests
|
||||
var pm = new PromptManager();
|
||||
var prompt = pm.GetSystemPrompt(AgentType.Default);
|
||||
Assert.Contains("心脏", prompt);
|
||||
Assert.Contains("阿福", prompt);
|
||||
Assert.Contains("温暖", prompt);
|
||||
Assert.Contains("健康", prompt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,283 +0,0 @@
|
||||
"""
|
||||
健康管家 - 全流程端到端测试
|
||||
模拟真实用户操作:注册→登录→各Agent对话→数据录入→查询验证
|
||||
"""
|
||||
import urllib.request, urllib.parse, json, sys, time, os
|
||||
|
||||
BASE = "http://localhost:5000"
|
||||
PASSED = 0
|
||||
FAILED = 0
|
||||
TOKEN = None
|
||||
|
||||
def api(method, path, data=None, token=None, files=None):
|
||||
"""调用后端 API"""
|
||||
url = f"{BASE}{path}"
|
||||
headers = {"Content-Type": "application/json"}
|
||||
if token:
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
|
||||
body = None
|
||||
if data:
|
||||
body = json.dumps(data, ensure_ascii=False).encode("utf-8")
|
||||
|
||||
req = urllib.request.Request(url, data=body, headers=headers, method=method)
|
||||
try:
|
||||
resp = urllib.request.urlopen(req, timeout=30)
|
||||
return json.loads(resp.read().decode("utf-8"))
|
||||
except Exception as e:
|
||||
return {"error": str(e), "code": -1}
|
||||
|
||||
def check(name, condition, detail=""):
|
||||
global PASSED, FAILED
|
||||
if condition:
|
||||
PASSED += 1
|
||||
print(f" [PASS] {name}")
|
||||
else:
|
||||
FAILED += 1
|
||||
print(f" [FAIL] {name} {detail}")
|
||||
|
||||
def login(phone="13800000001"):
|
||||
"""发送验证码 + 登录,返回 token"""
|
||||
sms = api("POST", "/api/auth/send-sms", {"phone": phone})
|
||||
code = sms.get("data", {}).get("devCode", "")
|
||||
if not code:
|
||||
return None
|
||||
result = api("POST", "/api/auth/login", {"phone": phone, "smsCode": code})
|
||||
return result.get("data", {}).get("accessToken")
|
||||
|
||||
def sse_stream(token, agent_type, message):
|
||||
"""连接 SSE 端点,返回所有事件"""
|
||||
url = f"{BASE}/api/ai/{agent_type}/chat?message={urllib.parse.quote(message)}&token={urllib.parse.quote(token or '')}"
|
||||
req = urllib.request.Request(url)
|
||||
events = []
|
||||
try:
|
||||
resp = urllib.request.urlopen(req, timeout=60)
|
||||
for line_bytes in resp:
|
||||
line = line_bytes.decode("utf-8").strip()
|
||||
if line.startswith("data: "):
|
||||
data = line[6:]
|
||||
if data == "[DONE]":
|
||||
break
|
||||
try:
|
||||
events.append(json.loads(data))
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
events.append({"error": str(e)})
|
||||
return events
|
||||
|
||||
def section(title):
|
||||
print(f"\n{'='*60}")
|
||||
print(f" {title}")
|
||||
print(f"{'='*60}")
|
||||
|
||||
# ============================================================
|
||||
section("1. 认证流程")
|
||||
# ============================================================
|
||||
print(" 1.1 发送验证码...")
|
||||
sms = api("POST", "/api/auth/send-sms", {"phone": "13800000001"})
|
||||
check("发送验证码", sms.get("code") == 0, str(sms.get("message","")))
|
||||
code = sms.get("data", {}).get("devCode", "")
|
||||
|
||||
print(" 1.2 验证码登录...")
|
||||
login_result = api("POST", "/api/auth/login", {"phone": "13800000001", "smsCode": code})
|
||||
check("登录成功", login_result.get("code") == 0)
|
||||
TOKEN = login_result.get("data", {}).get("accessToken", "")
|
||||
REFRESH = login_result.get("data", {}).get("refreshToken", "")
|
||||
check("返回accessToken", len(TOKEN) > 50)
|
||||
check("返回refreshToken", len(REFRESH) > 20)
|
||||
|
||||
print(" 1.3 刷新Token...")
|
||||
refresh_result = api("POST", "/api/auth/refresh", {"refreshToken": REFRESH})
|
||||
check("刷新Token成功", refresh_result.get("code") == 0)
|
||||
check("下发新Token", len(refresh_result.get("data", {}).get("accessToken", "")) > 50)
|
||||
|
||||
print(" 1.4 登出...")
|
||||
logout_result = api("POST", "/api/auth/logout", {"refreshToken": REFRESH})
|
||||
check("登出成功", logout_result.get("code") == 0)
|
||||
|
||||
# 重新登录获取token
|
||||
TOKEN = login()
|
||||
|
||||
# ============================================================
|
||||
section("2. 用户与档案")
|
||||
# ============================================================
|
||||
profile = api("GET", "/api/user/profile", token=TOKEN)
|
||||
check("获取个人信息", profile.get("code") == 0)
|
||||
|
||||
archive = api("GET", "/api/user/health-archive", token=TOKEN)
|
||||
check("获取健康档案", archive.get("code") == 0)
|
||||
check("档案有诊断信息", archive.get("data", {}).get("diagnosis") is not None if archive.get("data") else False,
|
||||
"诊断=" + str(archive.get("data", {}).get("diagnosis", "无")))
|
||||
|
||||
# ============================================================
|
||||
section("3. 健康数据 CRUD")
|
||||
# ============================================================
|
||||
print(" 3.1 录入血压...")
|
||||
bp = api("POST", "/api/health-records", token=TOKEN, data={
|
||||
"type": "BloodPressure", "systolic": 128, "diastolic": 82,
|
||||
"unit": "mmHg", "source": "Manual"
|
||||
})
|
||||
check("录入血压", bp.get("code") == 0, str(bp.get("message","")))
|
||||
|
||||
print(" 3.2 录入心率...")
|
||||
hr = api("POST", "/api/health-records", token=TOKEN, data={
|
||||
"type": "HeartRate", "value": 72, "unit": "次/分", "source": "Manual"
|
||||
})
|
||||
check("录入心率", hr.get("code") == 0, str(hr.get("message","")))
|
||||
|
||||
print(" 3.3 录入血糖...")
|
||||
glu = api("POST", "/api/health-records", token=TOKEN, data={
|
||||
"type": "Glucose", "value": 5.5, "unit": "mmol/L", "source": "Manual"
|
||||
})
|
||||
check("录入血糖", glu.get("code") == 0, str(glu.get("message","")))
|
||||
|
||||
print(" 3.4 录入血氧...")
|
||||
spo2 = api("POST", "/api/health-records", token=TOKEN, data={
|
||||
"type": "SpO2", "value": 98, "unit": "%", "source": "Manual"
|
||||
})
|
||||
check("录入血氧", spo2.get("code") == 0, str(spo2.get("message","")))
|
||||
|
||||
print(" 3.5 获取最新数据...")
|
||||
latest = api("GET", "/api/health-records/latest", token=TOKEN)
|
||||
check("获取最新数据", latest.get("code") == 0)
|
||||
check("血压存在", latest.get("data", {}).get("BloodPressure") is not None)
|
||||
|
||||
print(" 3.6 获取趋势数据...")
|
||||
trend = api("GET", "/api/health-records/trend?type=HeartRate&period=7", token=TOKEN)
|
||||
check("获取趋势数据", trend.get("code") == 0)
|
||||
|
||||
# ============================================================
|
||||
section("4. 用药管理")
|
||||
# ============================================================
|
||||
print(" 4.1 获取用药列表...")
|
||||
meds = api("GET", "/api/medications", token=TOKEN)
|
||||
check("获取用药列表", meds.get("code") == 0)
|
||||
|
||||
print(" 4.2 添加用药...")
|
||||
new_med = api("POST", "/api/medications", token=TOKEN, data={
|
||||
"name": "阿司匹林", "dosage": "100mg", "frequency": "Daily",
|
||||
"timeOfDay": ["08:00"], "source": "Manual", "startDate": "2026-06-02"
|
||||
})
|
||||
check("添加用药", new_med.get("code") == 0, str(new_med.get("message","")))
|
||||
med_id = new_med.get("data", {}).get("id", "")
|
||||
|
||||
print(" 4.3 服药打卡...")
|
||||
if med_id:
|
||||
confirm = api("POST", f"/api/medications/{med_id}/confirm", token=TOKEN)
|
||||
check("服药打卡", confirm.get("code") == 0, str(confirm.get("message","")))
|
||||
|
||||
# ============================================================
|
||||
section("5. 饮食记录")
|
||||
# ============================================================
|
||||
diet = api("GET", "/api/diet-records?date=2026-06-02", token=TOKEN)
|
||||
check("查询饮食记录", diet.get("code") == 0)
|
||||
|
||||
# ============================================================
|
||||
section("6. 运动计划")
|
||||
# ============================================================
|
||||
print(" 6.1 获取当前计划...")
|
||||
plan = api("GET", "/api/exercise-plans/current", token=TOKEN)
|
||||
check("获取当前计划", plan.get("code") == 0)
|
||||
|
||||
print(" 6.2 创建运动计划...")
|
||||
new_plan = api("POST", "/api/exercise-plans", token=TOKEN, data={
|
||||
"weekStartDate": "2026-06-02",
|
||||
"items": [
|
||||
{"dayOfWeek": 1, "exerciseType": "散步", "durationMinutes": 30, "isRestDay": False},
|
||||
{"dayOfWeek": 3, "exerciseType": "太极", "durationMinutes": 40, "isRestDay": False},
|
||||
{"dayOfWeek": 5, "exerciseType": "散步", "durationMinutes": 30, "isRestDay": False},
|
||||
]
|
||||
})
|
||||
check("创建运动计划", new_plan.get("code") == 0, str(new_plan.get("message","")))
|
||||
|
||||
# ============================================================
|
||||
section("7. 医生与问诊")
|
||||
# ============================================================
|
||||
print(" 7.1 医生列表...")
|
||||
docs = api("GET", "/api/doctors", token=TOKEN)
|
||||
check("获取医生列表", docs.get("code") == 0)
|
||||
check("有医生数据", len(docs.get("data", [])) > 0, f"共{len(docs.get('data',[]))}位医生")
|
||||
|
||||
print(" 7.2 问诊配额...")
|
||||
quota = api("GET", "/api/user/consultation-quota", token=TOKEN)
|
||||
check("获取问诊配额", quota.get("code") == 0)
|
||||
|
||||
# ============================================================
|
||||
section("8. AI 智能体对话")
|
||||
# ============================================================
|
||||
agents_to_test = [
|
||||
("default", "你好,介绍一下你自己"),
|
||||
("health", "我血压128/82"),
|
||||
("medication", "我现在在吃什么药"),
|
||||
("consultation", "最近胸口有点不舒服"),
|
||||
("diet", "我中午吃了红烧肉和米饭"),
|
||||
("exercise", "帮我查询运动计划"),
|
||||
]
|
||||
for agent_name, msg in agents_to_test:
|
||||
print(f" 8.{agents_to_test.index((agent_name,msg))+1} {agent_name} Agent: \"{msg[:30]}...\"")
|
||||
TOKEN = login() # fresh token
|
||||
events = sse_stream(TOKEN, agent_name, msg)
|
||||
|
||||
has_answer = any(e.get("action") == "answer" for e in events)
|
||||
has_tool = any(e.get("action") == "tool_result" for e in events)
|
||||
has_conv_id = any(e.get("action") == "conversation_id" for e in events)
|
||||
errors = [e for e in events if e.get("action") == "error"]
|
||||
|
||||
check(f"{agent_name}: 对话建立", has_conv_id)
|
||||
check(f"{agent_name}: 有回复", has_answer or has_tool,
|
||||
f"(events: {len(events)}, tools: {has_tool}, answer: {has_answer})")
|
||||
check(f"{agent_name}: 无错误", len(errors) == 0,
|
||||
f"errors: {[e.get('message','') for e in errors]}" if errors else "")
|
||||
|
||||
# ============================================================
|
||||
section("9. 对话历史")
|
||||
# ============================================================
|
||||
convs = api("GET", "/api/ai/conversations", token=TOKEN)
|
||||
check("获取对话列表", convs.get("code") == 0)
|
||||
check("有对话记录", len(convs.get("data", [])) > 0, f"共{len(convs.get('data',[]))}条")
|
||||
|
||||
# ============================================================
|
||||
section("10. VLM 食物识别")
|
||||
# ============================================================
|
||||
# 尝试上传测试图片
|
||||
test_img = "D:/health_project/食堂三菜一饭热量估算.png"
|
||||
if os.path.exists(test_img):
|
||||
# Use subprocess for multipart upload
|
||||
import subprocess
|
||||
cmd = [
|
||||
'curl', '-s', '--max-time', '30', '-X', 'POST',
|
||||
f'{BASE}/api/ai/analyze-food-image',
|
||||
'-H', f'Authorization: Bearer {TOKEN}',
|
||||
'-F', f'images=@{test_img}'
|
||||
]
|
||||
r = subprocess.run(cmd, capture_output=True, text=True)
|
||||
try:
|
||||
vlm = json.loads(r.stdout)
|
||||
check("VLM食物识别调通", vlm.get("code") == 0, str(vlm.get("message","")))
|
||||
has_data = bool(vlm.get("data", ""))
|
||||
check("VLM返回数据", has_data, f"data长度: {len(str(vlm.get('data','')))}")
|
||||
except:
|
||||
check("VLM食物识别", False, "JSON解析失败")
|
||||
else:
|
||||
check("VLM测试图片存在", False, f"{test_img} 不存在")
|
||||
|
||||
# ============================================================
|
||||
section("11. 报告列表")
|
||||
# ============================================================
|
||||
reports = api("GET", "/api/reports", token=TOKEN)
|
||||
check("获取报告列表", reports.get("code") == 0)
|
||||
|
||||
# ============================================================
|
||||
section("12. 通知偏好")
|
||||
# ============================================================
|
||||
notifs = api("GET", "/api/notifications/preferences", token=TOKEN)
|
||||
check("获取通知偏好", notifs.get("code") == 0)
|
||||
|
||||
# ============================================================
|
||||
print(f"\n{'='*60}")
|
||||
print(f" 测试结果: PASS={PASSED} FAIL={FAILED} TOTAL={PASSED+FAILED}")
|
||||
print(f"{'='*60}")
|
||||
|
||||
if FAILED > 0:
|
||||
sys.exit(1)
|
||||
BIN
health_app/flutter_01.png
Normal file
|
After Width: | Height: | Size: 557 KiB |
BIN
health_app/flutter_02.png
Normal file
|
After Width: | Height: | Size: 558 KiB |
@@ -1,3 +1,4 @@
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'local_database.dart';
|
||||
|
||||
@@ -54,6 +55,19 @@ class ApiClient {
|
||||
Future<Response> delete(String path) async {
|
||||
return _dio.delete(path);
|
||||
}
|
||||
|
||||
/// 上传文件(multipart),返回文件 URL
|
||||
Future<String?> uploadFile(String path, File file, {String fieldName = 'file'}) async {
|
||||
final formData = FormData.fromMap({
|
||||
fieldName: await MultipartFile.fromFile(file.path, filename: file.path.split('/').last),
|
||||
});
|
||||
final res = await _dio.post(path, data: formData);
|
||||
final data = res.data;
|
||||
if (data is Map) {
|
||||
return data['url']?.toString() ?? data['data']?['url']?.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 认证拦截器:自动注入 token + 401 刷新
|
||||
|
||||
@@ -4,10 +4,14 @@ import '../pages/auth/login_page.dart';
|
||||
import '../pages/home/home_page.dart';
|
||||
import '../pages/chart/trend_page.dart';
|
||||
import '../pages/medication/medication_list_page.dart';
|
||||
import '../pages/medication/medication_edit_page.dart';
|
||||
import '../pages/report/report_pages.dart';
|
||||
import '../pages/report/ai_analysis_page.dart';
|
||||
import '../pages/consultation/consultation_pages.dart';
|
||||
import '../pages/settings/settings_pages.dart';
|
||||
import '../pages/settings/notification_prefs_page.dart';
|
||||
import '../pages/profile/profile_page.dart';
|
||||
import '../pages/profile/profile_detail_page.dart';
|
||||
import '../pages/diet/diet_capture_page.dart';
|
||||
import '../pages/remaining_pages.dart';
|
||||
|
||||
@@ -25,14 +29,14 @@ Widget buildPage(RouteInfo route) {
|
||||
return const HealthCalendarPage();
|
||||
case 'medications':
|
||||
return const MedicationListPage();
|
||||
case 'medicationAdd':
|
||||
return const MedicationEditPage();
|
||||
case 'medicationEdit':
|
||||
return MedicationEditPage(id: params['id']);
|
||||
return const MedicationEditPage();
|
||||
case 'reports':
|
||||
return const ReportListPage();
|
||||
case 'reportDetail':
|
||||
return ReportDetailPage(id: params['id']!);
|
||||
case 'aiAnalysis':
|
||||
return const AiAnalysisPage();
|
||||
case 'doctors':
|
||||
return const DoctorListPage();
|
||||
case 'consultation':
|
||||
@@ -46,7 +50,11 @@ Widget buildPage(RouteInfo route) {
|
||||
case 'profile':
|
||||
return const ProfilePage();
|
||||
case 'profileEdit':
|
||||
return const ProfileDetailPage();
|
||||
case 'editProfile':
|
||||
return const EditProfilePage();
|
||||
case 'devices':
|
||||
return const DeviceManagementPage();
|
||||
case 'healthArchive':
|
||||
return const HealthArchivePage();
|
||||
case 'followups':
|
||||
|
||||
@@ -1,77 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 健康管家主题配置——薰衣草紫 + 温暖治愈风
|
||||
/// 健康管家 — Lavender Breeze 淡紫清风
|
||||
class AppTheme {
|
||||
AppTheme._();
|
||||
|
||||
static const Color primaryColor = Color(0xFF635BFF);
|
||||
static const Color primaryLight = Color(0xFFEDEBFF);
|
||||
static const Color primaryDark = Color(0xFF4B44D6);
|
||||
static const Color background = Color(0xFFF8F9FF);
|
||||
static const Color cardWhite = Color(0xFFFFFFFF);
|
||||
static const Color textPrimary = Color(0xFF1A1A1A);
|
||||
static const Color textSecondary = Color(0xFF666666);
|
||||
static const Color textPlaceholder = Color(0xFF999999);
|
||||
static const Color successGreen = Color(0xFF43A047);
|
||||
static const Color errorRed = Color(0xFFE53935);
|
||||
static const Color warningYellow = Color(0xFFF9A825);
|
||||
static const Color secondaryButton = Color(0xFFE5E5F7);
|
||||
static const Color primary = Color(0xFF8B9CF7); // 淡薰紫
|
||||
static const Color primaryLight = Color(0xFFF0F2FF); // 极淡紫底
|
||||
static const Color primaryDark = Color(0xFF6A7DE0); // 深薰紫
|
||||
|
||||
static const Color bg = Color(0xFFF8F9FC); // 清透白底
|
||||
static const Color surface = Color(0xFFFFFFFF); // 纯白卡片
|
||||
|
||||
static const Color text = Color(0xFF2D2B32);
|
||||
static const Color textSub = Color(0xFF8A8892);
|
||||
static const Color textHint = Color(0xFFBFBCC4);
|
||||
|
||||
static const Color success = Color(0xFF6ECF8A);
|
||||
static const Color error = Color(0xFFF56C6C);
|
||||
static const Color warning = Color(0xFFF5A623);
|
||||
static const Color accent = Color(0xFFFF8068);
|
||||
|
||||
static const Color border = Color(0xFFEAEAF0);
|
||||
static const Color divider = Color(0xFFF2F2F6);
|
||||
|
||||
/// 每个智能体的卡片色调
|
||||
static const Map<String, Color> agentColors = {
|
||||
'default': Color(0xFFE8ECFF), // 淡蓝紫
|
||||
'consultation': Color(0xFFE8F5FF), // 淡天蓝
|
||||
'health': Color(0xFFE8FFF0), // 淡薄荷
|
||||
'diet': Color(0xFFFFF2E8), // 淡杏
|
||||
'medication': Color(0xFFFFE8F0), // 淡粉
|
||||
'report': Color(0xFFE8F4FF), // 淡水蓝
|
||||
'exercise': Color(0xFFF0E8FF), // 淡紫
|
||||
};
|
||||
|
||||
static Color agentLight(String? name) => agentColors[name] ?? primaryLight;
|
||||
|
||||
static ThemeData get lightTheme => ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: primaryColor,
|
||||
primary: primaryColor,
|
||||
surface: background,
|
||||
brightness: Brightness.light,
|
||||
),
|
||||
scaffoldBackgroundColor: background,
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: primary, primary: primary, surface: bg, brightness: Brightness.light),
|
||||
scaffoldBackgroundColor: bg,
|
||||
|
||||
appBarTheme: const AppBarTheme(
|
||||
backgroundColor: cardWhite,
|
||||
foregroundColor: textPrimary,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
),
|
||||
cardTheme: CardThemeData(
|
||||
color: cardWhite,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
backgroundColor: surface, foregroundColor: text, elevation: 0,
|
||||
centerTitle: true, scrolledUnderElevation: 0,
|
||||
titleTextStyle: TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: text),
|
||||
),
|
||||
|
||||
cardTheme: CardThemeData(color: surface, elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), margin: EdgeInsets.zero),
|
||||
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
filled: true,
|
||||
fillColor: cardWhite,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: secondaryButton, width: 1.5),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: secondaryButton, width: 1.5),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: primaryColor, width: 1.5),
|
||||
),
|
||||
hintStyle: const TextStyle(color: textPlaceholder, fontSize: 16),
|
||||
),
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
|
||||
textStyle: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
filled: true, fillColor: const Color(0xFFF4F5FA),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: primary, width: 1.5)),
|
||||
hintStyle: const TextStyle(color: textHint, fontSize: 15),
|
||||
),
|
||||
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(style: ElevatedButton.styleFrom(
|
||||
backgroundColor: primary, foregroundColor: Colors.white,
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
textStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600), elevation: 0,
|
||||
)),
|
||||
|
||||
dialogTheme: DialogThemeData(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(22))),
|
||||
|
||||
textTheme: const TextTheme(
|
||||
headlineLarge: TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: textPrimary),
|
||||
titleLarge: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: textPrimary),
|
||||
bodyLarge: TextStyle(fontSize: 18, fontWeight: FontWeight.w400, color: textPrimary),
|
||||
bodyMedium: TextStyle(fontSize: 16, fontWeight: FontWeight.w400, color: textSecondary),
|
||||
labelMedium: TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: textSecondary),
|
||||
labelSmall: TextStyle(fontSize: 12, fontWeight: FontWeight.w400, color: textSecondary),
|
||||
headlineLarge: TextStyle(fontSize: 24, fontWeight: FontWeight.w700, color: text),
|
||||
titleLarge: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: text),
|
||||
titleMedium: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: text),
|
||||
bodyLarge: TextStyle(fontSize: 16, color: text, height: 1.5),
|
||||
bodyMedium: TextStyle(fontSize: 15, color: textSub, height: 1.4),
|
||||
labelMedium: TextStyle(fontSize: 13, color: textSub),
|
||||
labelSmall: TextStyle(fontSize: 11, color: textHint),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
/// 路由信息
|
||||
|
||||
@@ -3,12 +3,10 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
import '../../providers/auth_provider.dart';
|
||||
|
||||
/// 登录页——手机号 + 验证码
|
||||
class LoginPage extends ConsumerStatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<LoginPage> createState() => _LoginPageState();
|
||||
@override ConsumerState<LoginPage> createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
@@ -20,165 +18,70 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
bool _loading = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_phoneCtrl.dispose();
|
||||
_codeCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@override void dispose() { _phoneCtrl.dispose(); _codeCtrl.dispose(); super.dispose(); }
|
||||
|
||||
Future<void> _sendSms() async {
|
||||
final phone = _phoneCtrl.text.trim();
|
||||
if (phone.length != 11 || !phone.startsWith('1')) {
|
||||
setState(() => _error = '请输入正确的手机号');
|
||||
return;
|
||||
}
|
||||
if (phone.length != 11 || !phone.startsWith('1')) { setState(() => _error = '请输入正确的手机号'); return; }
|
||||
setState(() { _sending = true; _error = null; });
|
||||
final result = await ref.read(authProvider.notifier).sendSms(phone);
|
||||
setState(() { _sending = false; });
|
||||
if (result.error != null) {
|
||||
setState(() => _error = result.error);
|
||||
return;
|
||||
}
|
||||
// 开发阶段自动填充验证码
|
||||
if (result.devCode != null) {
|
||||
_codeCtrl.text = result.devCode!;
|
||||
}
|
||||
setState(() => _countdown = 60);
|
||||
_startCountdown();
|
||||
if (result.error != null) { setState(() => _error = result.error); return; }
|
||||
if (result.devCode != null) _codeCtrl.text = result.devCode!;
|
||||
setState(() => _countdown = 60); _startCountdown();
|
||||
}
|
||||
|
||||
void _startCountdown() async {
|
||||
for (var i = 60; i > 0; i--) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if (!mounted) return;
|
||||
setState(() => _countdown = i - 1);
|
||||
}
|
||||
for (var i = 60; i > 0; i--) { await Future.delayed(const Duration(seconds: 1)); if (!mounted) return; setState(() => _countdown = i - 1); }
|
||||
}
|
||||
|
||||
Future<void> _login() async {
|
||||
if (!_agreed) {
|
||||
setState(() => _error = '请阅读并同意服务协议和隐私政策');
|
||||
return;
|
||||
}
|
||||
if (!_agreed) { setState(() => _error = '请阅读并同意服务协议和隐私政策'); return; }
|
||||
setState(() { _loading = true; _error = null; });
|
||||
final err = await ref.read(authProvider.notifier).login(
|
||||
_phoneCtrl.text.trim(),
|
||||
_codeCtrl.text.trim(),
|
||||
);
|
||||
setState(() => _loading = false);
|
||||
if (err != null) {
|
||||
setState(() => _error = err);
|
||||
return;
|
||||
}
|
||||
final err = await ref.read(authProvider.notifier).login(_phoneCtrl.text.trim(), _codeCtrl.text.trim());
|
||||
setState(() => _loading = false );
|
||||
if (err != null) { setState(() => _error = err); return; }
|
||||
goRoute(ref, 'home');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@override Widget build(BuildContext context) {
|
||||
final authState = ref.watch(authProvider);
|
||||
|
||||
// 已登录直接跳转
|
||||
if (authState.isLoggedIn && !authState.isLoading) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => goRoute(ref, 'home'));
|
||||
}
|
||||
if (authState.isLoggedIn && !authState.isLoading) WidgetsBinding.instance.addPostFrameCallback((_) => goRoute(ref, 'home'));
|
||||
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 80),
|
||||
// Logo
|
||||
Icon(Icons.local_hospital, size: 64, color: Theme.of(context).colorScheme.primary),
|
||||
const SizedBox(height: 16),
|
||||
Text('健康管家', style: Theme.of(context).textTheme.headlineLarge),
|
||||
const SizedBox(height: 8),
|
||||
Text('您的 AI 健康陪伴助手', style: Theme.of(context).textTheme.bodyMedium),
|
||||
const SizedBox(height: 48),
|
||||
|
||||
// 手机号
|
||||
TextField(
|
||||
controller: _phoneCtrl,
|
||||
keyboardType: TextInputType.phone,
|
||||
maxLength: 11,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '手机号',
|
||||
prefixText: '+86 ',
|
||||
counterText: '',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 验证码
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _codeCtrl,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 6,
|
||||
decoration: const InputDecoration(hintText: '验证码', counterText: ''),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
SizedBox(
|
||||
width: 120,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed: (_countdown > 0 || _sending) ? null : _sendSms,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _countdown > 0 ? Colors.grey[300] : null,
|
||||
),
|
||||
child: Text(
|
||||
_sending ? '发送中' : _countdown > 0 ? '${_countdown}s' : '获取验证码',
|
||||
style: TextStyle(fontSize: 14, color: _countdown > 0 ? Colors.grey[600] : null),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 协议勾选
|
||||
Row(
|
||||
children: [
|
||||
Checkbox(value: _agreed, onChanged: (v) => setState(() => _agreed = v ?? false)),
|
||||
GestureDetector(
|
||||
onTap: () => setState(() => _agreed = !_agreed),
|
||||
child: Text('已阅读并同意《服务协议》《隐私政策》', style: Theme.of(context).textTheme.labelMedium),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 登录按钮
|
||||
if (_error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Text(_error!, style: const TextStyle(color: AppColors.errorRed, fontSize: 14)),
|
||||
),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed: _loading ? null : _login,
|
||||
child: _loading
|
||||
? const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
: const Text('登 录'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 80),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(gradient: LinearGradient(begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [Color(0xFFF0F2FF), Color(0xFFF0F2FF), Color(0xFFE8E4FF)])),
|
||||
child: SafeArea(child: SingleChildScrollView(padding: const EdgeInsets.symmetric(horizontal: 32), child: Column(children: [
|
||||
const SizedBox(height: 60),
|
||||
Container(width: 140, height: 140, decoration: BoxDecoration(color: const Color(0xFF8B9CF7).withAlpha(20), borderRadius: BorderRadius.circular(70)), child: Stack(alignment: Alignment.center, children: [
|
||||
Container(width: 100, height: 100, decoration: BoxDecoration(color: Colors.white.withAlpha(200), borderRadius: BorderRadius.circular(50)), child: Icon(Icons.favorite, size: 50, color: const Color(0xFF8B9CF7))),
|
||||
Positioned(right: 10, top: 10, child: Container(width: 30, height: 30, decoration: BoxDecoration(color: const Color(0xFFFFB800), borderRadius: BorderRadius.circular(15), border: Border.all(color: Colors.white, width: 2)), child: const Icon(Icons.add, size: 16, color: Colors.white))),
|
||||
])),
|
||||
const SizedBox(height: 24),
|
||||
Text('健康管家', style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold, color: const Color(0xFF1A1A1A))),
|
||||
const SizedBox(height: 8),
|
||||
Text('你的 AI 心脏健康管家', style: TextStyle(fontSize: 15, color: Colors.grey[500])),
|
||||
const SizedBox(height: 48),
|
||||
TextField(controller: _phoneCtrl, keyboardType: TextInputType.phone, maxLength: 11,
|
||||
decoration: InputDecoration(hintText: '请输入手机号', prefixIcon: const Padding(padding: EdgeInsets.only(left: 12), child: Text('+86', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500))), counterText: '', filled: true, fillColor: Colors.white, border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none), enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none), focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: Color(0xFF8B9CF7), width: 1.5)))),
|
||||
const SizedBox(height: 16),
|
||||
Row(children: [
|
||||
Expanded(child: TextField(controller: _codeCtrl, keyboardType: TextInputType.number, maxLength: 6,
|
||||
decoration: InputDecoration(hintText: '验证码', filled: true, fillColor: Colors.white, border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none), enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none), focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: Color(0xFF8B9CF7), width: 1.5)), counterText: ''))),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(onTap: (_countdown > 0 || _sending) ? null : _sendSms, child: Container(width: 100, height: 48, alignment: Alignment.center, decoration: BoxDecoration(color: _countdown > 0 ? Colors.grey[300] : const Color(0xFF8B9CF7), borderRadius: BorderRadius.circular(12)), child: Text(_sending ? '发送中' : _countdown > 0 ? '${_countdown}s' : '获取验证码', style: TextStyle(fontSize: 14, color: _countdown > 0 ? Colors.grey[600] : Colors.white, fontWeight: FontWeight.w500)))),
|
||||
]),
|
||||
const SizedBox(height: 8),
|
||||
Align(alignment: Alignment.centerLeft, child: GestureDetector(onTap: () => setState(() => _agreed = !_agreed), child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(width: 20, height: 20, margin: const EdgeInsets.only(right: 6), decoration: BoxDecoration(shape: BoxShape.rectangle, color: _agreed ? const Color(0xFF8B9CF7) : Colors.transparent, border: Border.all(color: _agreed ? const Color(0xFF8B9CF7) : const Color(0xFFBDBDBD), width: 1.5), borderRadius: BorderRadius.circular(4)), child: _agreed ? const Icon(Icons.check, size: 14, color: Colors.white) : null),
|
||||
RichText(text: TextSpan(children: [TextSpan(text: '已阅读并同意', style: TextStyle(fontSize: 13, color: Colors.grey[600])), TextSpan(text: '《服务协议》', style: const TextStyle(fontSize: 13, color: Color(0xFF8B9CF7))), TextSpan(text: '和', style: TextStyle(fontSize: 13, color: Colors.grey[600])), TextSpan(text: '《隐私政策》', style: const TextStyle(fontSize: 13, color: Color(0xFF8B9CF7)))])),
|
||||
]))),
|
||||
if (_error != null) Padding(padding: const EdgeInsets.only(top: 12), child: Text(_error!, style: const TextStyle(color: Color(0xFFE53935), fontSize: 13))),
|
||||
const SizedBox(height: 24),
|
||||
GestureDetector(onTap: _loading ? null : _login, child: Container(width: double.infinity, height: 50, alignment: Alignment.center, decoration: BoxDecoration(gradient: const LinearGradient(colors: [Color(0xFFA8B5FA), Color(0xFF8B9CF7)]), borderRadius: BorderRadius.circular(25), boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(80), blurRadius: 16, offset: const Offset(0, 8))]), child: _loading ? const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2.5, color: Colors.white)) : const Text('登 录', style: TextStyle(fontSize: 17, color: Colors.white, fontWeight: FontWeight.w600, letterSpacing: 2)))),
|
||||
const SizedBox(height: 40),
|
||||
]))),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 引用 AppTheme 颜色
|
||||
class AppColors {
|
||||
static const Color errorRed = Color(0xFFE53935);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
import '../../providers/data_providers.dart';
|
||||
|
||||
/// 医生列表页
|
||||
@@ -35,10 +36,10 @@ class DoctorListPage extends ConsumerWidget {
|
||||
child: Row(children: [
|
||||
CircleAvatar(
|
||||
radius: 28,
|
||||
backgroundColor: const Color(0xFFEDEBFF),
|
||||
backgroundColor: const Color(0xFFF0F2FF),
|
||||
child: Text(
|
||||
(d['name'] as String?)?.isNotEmpty == true ? d['name']![0] : '?',
|
||||
style: const TextStyle(fontSize: 22, color: Color(0xFF635BFF)),
|
||||
style: const TextStyle(fontSize: 22, color: Color(0xFF8B9CF7)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
@@ -52,16 +53,14 @@ class DoctorListPage extends ConsumerWidget {
|
||||
Text(d['title'] ?? '', style: const TextStyle(fontSize: 14, color: Color(0xFF666666))),
|
||||
]),
|
||||
const SizedBox(height: 4),
|
||||
Text(d['department'] ?? '', style: const TextStyle(fontSize: 14, color: Color(0xFF635BFF))),
|
||||
Text(d['department'] ?? '', style: const TextStyle(fontSize: 14, color: Color(0xFF8B9CF7))),
|
||||
const SizedBox(height: 2),
|
||||
Text(d['introduction'] ?? '', style: const TextStyle(fontSize: 14, color: Color(0xFF999999))),
|
||||
],
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
// TODO: 点击「咨询」创建问诊并跳转聊天页
|
||||
},
|
||||
onPressed: () => pushRoute(ref, 'consultation', params: {'id': d['id']?.toString() ?? ''}),
|
||||
child: const Text('咨询'),
|
||||
),
|
||||
]),
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
|
||||
final dietProvider = NotifierProvider<DietNotifier, DietState>(DietNotifier.new);
|
||||
|
||||
@@ -131,11 +132,11 @@ class DietCapturePage extends ConsumerWidget {
|
||||
width: 180,
|
||||
height: 180,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F3FF),
|
||||
color: const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(90),
|
||||
border: Border.all(color: const Color(0xFF635BFF), width: 2),
|
||||
border: Border.all(color: const Color(0xFF8B9CF7), width: 2),
|
||||
),
|
||||
child: const Icon(Icons.camera_alt, size: 48, color: Color(0xFF635BFF)),
|
||||
child: const Icon(Icons.camera_alt, size: 48, color: Color(0xFF8B9CF7)),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text('拍摄或上传您的餐食照片', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
|
||||
@@ -164,10 +165,10 @@ class DietCapturePage extends ConsumerWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFEFEFF),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF635BFF).withAlpha(20), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(20), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: IconButton(
|
||||
icon: Icon(icon, size: 32, color: const Color(0xFF635BFF)),
|
||||
icon: Icon(icon, size: 32, color: const Color(0xFF8B9CF7)),
|
||||
onPressed: () => _pickImage(context, ref, source),
|
||||
),
|
||||
),
|
||||
@@ -243,11 +244,11 @@ class DietCapturePage extends ConsumerWidget {
|
||||
child: Column(children: [
|
||||
Text(meal['icon']!, style: const TextStyle(fontSize: 20)),
|
||||
const SizedBox(height: 4),
|
||||
Text(meal['label']!, style: TextStyle(fontSize: 12, color: isSelected ? Colors.white : const Color(0xFF635BFF))),
|
||||
Text(meal['label']!, style: TextStyle(fontSize: 12, color: isSelected ? Colors.white : const Color(0xFF8B9CF7))),
|
||||
]),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: isSelected ? const Color(0xFF635BFF) : const Color(0xFFF5F3FF),
|
||||
foregroundColor: isSelected ? Colors.white : const Color(0xFF635BFF),
|
||||
backgroundColor: isSelected ? const Color(0xFF8B9CF7) : const Color(0xFFF0F2FF),
|
||||
foregroundColor: isSelected ? Colors.white : const Color(0xFF8B9CF7),
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
@@ -267,10 +268,10 @@ class DietCapturePage extends ConsumerWidget {
|
||||
height: 60,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEDEBFF),
|
||||
color: const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
),
|
||||
child: const CircularProgressIndicator(strokeWidth: 3, color: Color(0xFF635BFF)),
|
||||
child: const CircularProgressIndicator(strokeWidth: 3, color: Color(0xFF8B9CF7)),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('AI 正在识别食物...', style: TextStyle(fontSize: 16, color: Color(0xFF666666))),
|
||||
@@ -285,7 +286,7 @@ class DietCapturePage extends ConsumerWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFEFEFF),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: const Color(0xFFE8E6FF), width: 1.5),
|
||||
border: Border.all(color: const Color(0xFFD8DCFD), width: 1.5),
|
||||
),
|
||||
child: Column(children: [
|
||||
Padding(
|
||||
@@ -296,7 +297,7 @@ class DietCapturePage extends ConsumerWidget {
|
||||
const Text('识别结果', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add, size: 20, color: Color(0xFF635BFF)),
|
||||
icon: const Icon(Icons.add, size: 20, color: Color(0xFF8B9CF7)),
|
||||
onPressed: () => ref.read(dietProvider.notifier).addFood(),
|
||||
),
|
||||
]),
|
||||
@@ -311,14 +312,14 @@ class DietCapturePage extends ConsumerWidget {
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: food.selected ? const Color(0xFFF5F3FF) : const Color(0xFFF5F5F5),
|
||||
color: food.selected ? const Color(0xFFF0F2FF) : const Color(0xFFF5F5F5),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(children: [
|
||||
Checkbox(
|
||||
value: food.selected,
|
||||
onChanged: (v) => ref.read(dietProvider.notifier).toggleFood(food.id),
|
||||
activeColor: const Color(0xFF635BFF),
|
||||
activeColor: const Color(0xFF8B9CF7),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
@@ -338,7 +339,7 @@ class DietCapturePage extends ConsumerWidget {
|
||||
controller: TextEditingController(text: food.calories.toString()),
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (v) => ref.read(dietProvider.notifier).updateFoodCalories(food.id, int.tryParse(v) ?? 0),
|
||||
style: TextStyle(fontSize: 12, color: const Color(0xFF635BFF)),
|
||||
style: TextStyle(fontSize: 12, color: const Color(0xFF8B9CF7)),
|
||||
),
|
||||
),
|
||||
const Text('kcal', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
|
||||
@@ -357,7 +358,7 @@ class DietCapturePage extends ConsumerWidget {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F3FF),
|
||||
color: const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(children: [
|
||||
@@ -382,7 +383,7 @@ class DietCapturePage extends ConsumerWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFEFEFF),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: const Color(0xFFE8E6FF), width: 1.5),
|
||||
border: Border.all(color: const Color(0xFFD8DCFD), width: 1.5),
|
||||
),
|
||||
child: Column(children: [
|
||||
const Text('🥗 健康评分', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
@@ -416,7 +417,7 @@ class DietCapturePage extends ConsumerWidget {
|
||||
switch (score) {
|
||||
case 1: return const Color(0xFFE53935);
|
||||
case 2: return const Color(0xFFF9A825);
|
||||
case 3: return const Color(0xFF635BFF);
|
||||
case 3: return const Color(0xFF8B9CF7);
|
||||
case 4: return const Color(0xFF43A047);
|
||||
case 5: return const Color(0xFF00C853);
|
||||
default: return Colors.grey[400]!;
|
||||
@@ -430,13 +431,13 @@ class DietCapturePage extends ConsumerWidget {
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('饮食记录已保存 ✅'),
|
||||
backgroundColor: Color(0xFF635BFF),
|
||||
backgroundColor: Color(0xFF8B9CF7),
|
||||
));
|
||||
Navigator.pop(context);
|
||||
popRoute(ref);
|
||||
},
|
||||
child: const Text('保存记录'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF635BFF),
|
||||
backgroundColor: const Color(0xFF8B9CF7),
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
|
||||
@@ -2,534 +2,226 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import '../../core/api_client.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
import 'dart:io';
|
||||
import '../../providers/auth_provider.dart';
|
||||
import '../../providers/chat_provider.dart';
|
||||
import '../../providers/data_providers.dart';
|
||||
import '../../widgets/agent_bar.dart';
|
||||
import '../../widgets/health_drawer.dart';
|
||||
import 'widgets/chat_messages_view.dart';
|
||||
|
||||
/// 首页——主界面
|
||||
class HomePage extends ConsumerStatefulWidget {
|
||||
const HomePage({super.key});
|
||||
@override
|
||||
ConsumerState<HomePage> createState() => _HomePageState();
|
||||
@override ConsumerState<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends ConsumerState<HomePage> {
|
||||
final _textCtrl = TextEditingController();
|
||||
final _scrollCtrl = ScrollController();
|
||||
bool _taskCardsExpanded = true;
|
||||
bool _showExpandButton = false;
|
||||
String? _pickedImagePath;
|
||||
final Set<ActiveAgent> _welcomedAgents = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scrollCtrl.addListener(_onScroll);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_textCtrl.dispose();
|
||||
_scrollCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onScroll() {
|
||||
if (_scrollCtrl.offset > 50 && !_showExpandButton) {
|
||||
setState(() => _showExpandButton = true);
|
||||
} else if (_scrollCtrl.offset <= 50 && _showExpandButton) {
|
||||
setState(() => _showExpandButton = false);
|
||||
}
|
||||
}
|
||||
@override void initState() { super.initState(); }
|
||||
@override void dispose() { _textCtrl.dispose(); _scrollCtrl.dispose(); super.dispose(); }
|
||||
|
||||
void _sendMessage() {
|
||||
final text = _textCtrl.text.trim();
|
||||
if (text.isEmpty) return;
|
||||
final imagePath = _pickedImagePath;
|
||||
if (text.isEmpty && imagePath == null) return;
|
||||
_textCtrl.clear();
|
||||
ref.read(chatProvider.notifier).sendMessage(text);
|
||||
setState(() => _pickedImagePath = null);
|
||||
if (imagePath != null) {
|
||||
ref.read(chatProvider.notifier).sendImage(imagePath, text);
|
||||
} else {
|
||||
ref.read(chatProvider.notifier).sendMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@override Widget build(BuildContext context) {
|
||||
final chatState = ref.watch(chatProvider);
|
||||
final auth = ref.watch(authProvider);
|
||||
final user = auth.user;
|
||||
final selectedAgent = ref.watch(selectedAgentProvider);
|
||||
|
||||
ref.listen(cameraActionProvider, (prev, next) {
|
||||
if (next == 'camera') {
|
||||
_pickImage(ImageSource.camera);
|
||||
ref.read(cameraActionProvider.notifier).clear();
|
||||
} else if (next == 'gallery') {
|
||||
_pickImage(ImageSource.gallery);
|
||||
ref.read(cameraActionProvider.notifier).clear();
|
||||
}
|
||||
});
|
||||
|
||||
return Scaffold(
|
||||
drawer: const HealthDrawer(),
|
||||
backgroundColor: const Color(0xFFF8F9FC),
|
||||
body: SafeArea(
|
||||
child: Stack(children: [
|
||||
Column(children: [
|
||||
_buildHeader(context),
|
||||
if (_taskCardsExpanded) _buildTaskCards(),
|
||||
Expanded(child: ChatMessagesView(scrollCtrl: _scrollCtrl, messages: chatState.messages)),
|
||||
_buildAgentPanel(context, selectedAgent),
|
||||
const AgentBar(),
|
||||
_buildInputBar(),
|
||||
]),
|
||||
_buildExpandButton(),
|
||||
child: Column(children: [
|
||||
// ── 顶部栏 ──
|
||||
_buildHeader(user),
|
||||
|
||||
// ── 聊天区域(今日任务已移入对话流第一条消息) ──
|
||||
Expanded(child: ChatMessagesView(scrollCtrl: _scrollCtrl, messages: chatState.messages)),
|
||||
|
||||
// ── 底部合并区:智能体栏 + 操作面板 + 输入框(固定高度) ──
|
||||
_buildBottomBar(context, selectedAgent),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildExpandButton() {
|
||||
if (!_showExpandButton || _taskCardsExpanded) return const SizedBox.shrink();
|
||||
// ═════════════════════ 顶部栏 ═════════════════════
|
||||
|
||||
return Positioned(
|
||||
top: 60,
|
||||
right: 16,
|
||||
child: AnimatedOpacity(
|
||||
opacity: _showExpandButton ? 1.0 : 0.0,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: FloatingActionButton(
|
||||
onPressed: () => setState(() => _taskCardsExpanded = true),
|
||||
mini: true,
|
||||
backgroundColor: const Color(0xFF635BFF),
|
||||
child: const Icon(Icons.keyboard_arrow_down, size: 20),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
Widget _buildHeader(dynamic user) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
child: Row(children: [
|
||||
Builder(builder: (ctx) => IconButton(
|
||||
icon: const Icon(Icons.menu, size: 24),
|
||||
onPressed: () => Scaffold.of(ctx).openDrawer(),
|
||||
Builder(builder: (ctx) => GestureDetector(
|
||||
onTap: () => Scaffold.of(ctx).openDrawer(),
|
||||
child: CircleAvatar(radius: 20, backgroundColor: const Color(0xFFF0F2FF), backgroundImage: user?.avatarUrl != null ? NetworkImage(user!.avatarUrl!) : null, child: user?.avatarUrl == null ? const Icon(Icons.person, size: 24, color: Color(0xFF8B9CF7)) : null),
|
||||
)),
|
||||
const Spacer(),
|
||||
Text('健康管家', style: Theme.of(context).textTheme.titleLarge),
|
||||
const Spacer(),
|
||||
const SizedBox(width: 48),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Row(mainAxisSize: MainAxisSize.min, children: [Icon(Icons.smart_toy_outlined, size: 16, color: const Color(0xFF8B9CF7)), const SizedBox(width: 4), Text('AI 健康管家', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: Colors.grey[600]))]),
|
||||
const SizedBox(height: 2),
|
||||
Text('${_getGreeting()},${user?.name ?? '张三'}!', style: const TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: Color(0xFF1A1A1A))),
|
||||
])),
|
||||
Icon(Icons.notifications_none, size: 22, color: Colors.grey[600]),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTaskCards() {
|
||||
final latestHealth = ref.watch(latestHealthProvider);
|
||||
|
||||
return latestHealth.when(
|
||||
data: (data) {
|
||||
final tasks = _getTaskCards(data);
|
||||
if (tasks.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFEFEFF),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF635BFF).withAlpha(10), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Column(children: [
|
||||
Row(children: [
|
||||
const Icon(Icons.wb_sunny, size: 20, color: Color(0xFFFFB800)),
|
||||
const SizedBox(width: 8),
|
||||
Text(_getGreeting(), style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () => setState(() => _taskCardsExpanded = false),
|
||||
child: const Icon(Icons.keyboard_arrow_down, size: 22, color: Color(0xFF999999)),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 12),
|
||||
Column(children: tasks),
|
||||
]),
|
||||
);
|
||||
},
|
||||
loading: () => const SizedBox.shrink(),
|
||||
error: (_, __) {
|
||||
final tasks = _getTaskCards(const {});
|
||||
if (tasks.isEmpty) return const SizedBox.shrink();
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFEFEFF),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF635BFF).withAlpha(10), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Column(children: [
|
||||
Row(children: [
|
||||
const Icon(Icons.wb_sunny, size: 20, color: Color(0xFFFFB800)),
|
||||
const SizedBox(width: 8),
|
||||
Text(_getGreeting(), style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () => setState(() => _taskCardsExpanded = false),
|
||||
child: const Icon(Icons.keyboard_arrow_down, size: 22, color: Color(0xFF999999)),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 12),
|
||||
Column(children: tasks),
|
||||
]),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String _getGreeting() {
|
||||
final hour = DateTime.now().hour;
|
||||
if (hour < 6) return '夜深了';
|
||||
if (hour < 9) return '早上好';
|
||||
if (hour < 12) return '上午好';
|
||||
if (hour < 14) return '中午好';
|
||||
if (hour < 18) return '下午好';
|
||||
if (hour < 22) return '晚上好';
|
||||
return '夜深了';
|
||||
return '晚上好';
|
||||
}
|
||||
|
||||
List<Widget> _getTaskCards(Map<String, dynamic> healthData) {
|
||||
final cards = <Widget>[];
|
||||
// ═════════════════════ 智能体选择条(常驻) ═════════════════════
|
||||
|
||||
cards.add(_buildMedicationCard());
|
||||
cards.add(_buildExerciseCard());
|
||||
cards.add(_buildMeasurementCard());
|
||||
static final _agentDefs = [
|
||||
(ActiveAgent.consultation, '问诊', Icons.chat_bubble_outline),
|
||||
(ActiveAgent.health, '记数据', Icons.favorite_border),
|
||||
(ActiveAgent.diet, '拍饮食', Icons.restaurant_outlined),
|
||||
(ActiveAgent.medication, '药管家', Icons.medication_outlined),
|
||||
(ActiveAgent.report, '看报告', Icons.description_outlined),
|
||||
(ActiveAgent.exercise, '运动', Icons.directions_run_outlined),
|
||||
];
|
||||
|
||||
final abnormalCards = _buildAbnormalCards(healthData);
|
||||
cards.addAll(abnormalCards);
|
||||
|
||||
final summaryCard = _buildSummaryCard(healthData);
|
||||
if (summaryCard != null) cards.add(summaryCard);
|
||||
|
||||
return cards;
|
||||
}
|
||||
|
||||
Widget _buildMedicationCard() {
|
||||
return _buildTaskCard(
|
||||
'💊',
|
||||
'计划 8:00 吃 阿司匹林 100mg',
|
||||
Icons.check_circle_outline,
|
||||
() => _handleMedicationCheck(),
|
||||
type: 'medication',
|
||||
Widget _buildAgentBar(ActiveAgent? selected) {
|
||||
return Container(
|
||||
height: 36,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: _agentDefs.length,
|
||||
separatorBuilder: (_, i) => const SizedBox(width: 6),
|
||||
itemBuilder: (_, i) {
|
||||
final (agent, label, icon) = _agentDefs[i];
|
||||
final isActive = selected == agent;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
final notifier = ref.read(selectedAgentProvider.notifier);
|
||||
if (isActive) {
|
||||
notifier.select(null);
|
||||
} else {
|
||||
notifier.select(agent);
|
||||
ref.read(chatProvider.notifier).setAgent(agent);
|
||||
if (_welcomedAgents.add(agent)) {
|
||||
ref.read(chatProvider.notifier).insertAgentWelcome(agent);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? const Color(0xFF8B9CF7) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: isActive ? const Color(0xFF8B9CF7) : const Color(0xFFE0E0E0)),
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(icon, size: 13, color: isActive ? Colors.white : const Color(0xFF666666)),
|
||||
const SizedBox(width: 3),
|
||||
Text(label, style: TextStyle(fontSize: 11, fontWeight: isActive ? FontWeight.w600 : FontWeight.w500, color: isActive ? Colors.white : const Color(0xFF666666))),
|
||||
]),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildExerciseCard() {
|
||||
return _buildTaskCard(
|
||||
'🏃',
|
||||
'今日待运动:散步 30 分钟',
|
||||
Icons.check_circle_outline,
|
||||
() => _handleExerciseCheck(),
|
||||
type: 'exercise',
|
||||
);
|
||||
// ═════════════════════ 底部合并区:智能体栏 + 操作面板 + 输入框 ═════════════════════
|
||||
|
||||
Widget _buildBottomBar(BuildContext context, ActiveAgent? selectedAgent) {
|
||||
return Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
// 智能体胶囊栏(常驻,高度36)
|
||||
_buildAgentBar(selectedAgent),
|
||||
|
||||
// 图片预览(有选中图片时显示)
|
||||
if (_pickedImagePath != null) _buildImagePreview(),
|
||||
|
||||
// 输入框
|
||||
_buildCompactInputBar(context),
|
||||
]);
|
||||
}
|
||||
|
||||
Widget _buildMeasurementCard() {
|
||||
return _buildTaskCard(
|
||||
'🩺',
|
||||
'今日待测量:血压',
|
||||
Icons.arrow_forward_ios,
|
||||
() => _textCtrl.text = '血压 ',
|
||||
type: 'measurement',
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildAbnormalCards(Map<String, dynamic> healthData) {
|
||||
final cards = <Widget>[];
|
||||
|
||||
final bp = healthData['BloodPressure'];
|
||||
if (bp != null && bp is Map) {
|
||||
final systolic = bp['systolic'];
|
||||
final diastolic = bp['diastolic'];
|
||||
if (systolic != null && systolic >= 140) {
|
||||
cards.add(_buildTaskCard(
|
||||
'⚠️',
|
||||
'昨日血压 ${systolic}/${diastolic ?? '--'},偏高',
|
||||
Icons.arrow_forward_ios,
|
||||
() => pushRoute(ref, 'trend', params: {'type': 'blood_pressure'}),
|
||||
type: 'warning',
|
||||
highlight: true,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
final hr = healthData['HeartRate'];
|
||||
if (hr != null && hr is Map) {
|
||||
final value = hr['value'];
|
||||
if (value != null && (value > 100 || value < 60)) {
|
||||
cards.add(_buildTaskCard(
|
||||
'⚠️',
|
||||
'昨日心率 $value,${value > 100 ? '偏高' : '偏低'}',
|
||||
Icons.arrow_forward_ios,
|
||||
() => pushRoute(ref, 'trend', params: {'type': 'heart_rate'}),
|
||||
type: 'warning',
|
||||
highlight: true,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return cards;
|
||||
}
|
||||
|
||||
Widget? _buildSummaryCard(Map<String, dynamic> healthData) {
|
||||
final values = <String>[];
|
||||
|
||||
final bp = healthData['BloodPressure'];
|
||||
if (bp != null && bp is Map) {
|
||||
final sys = bp['systolic'];
|
||||
final dia = bp['diastolic'];
|
||||
if (sys != null && dia != null) values.add('血压 $sys/$dia');
|
||||
}
|
||||
|
||||
final hr = healthData['HeartRate'];
|
||||
if (hr != null && hr is Map && hr['value'] != null) {
|
||||
values.add('心率 ${hr['value']}');
|
||||
}
|
||||
|
||||
final glucose = healthData['Glucose'];
|
||||
if (glucose != null && glucose is Map && glucose['value'] != null) {
|
||||
values.add('血糖 ${glucose['value']}');
|
||||
}
|
||||
|
||||
if (values.isEmpty) return null;
|
||||
|
||||
return _buildTaskCard(
|
||||
'📊',
|
||||
'今日已记录:${values.join('、')}',
|
||||
Icons.arrow_forward_ios,
|
||||
() => pushRoute(ref, 'trend', params: {'type': 'blood_pressure'}),
|
||||
type: 'summary',
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTaskCard(String icon, String text, IconData actionIcon, VoidCallback onTap, {String type = '', bool highlight = false}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: highlight ? BoxDecoration(
|
||||
color: const Color(0xFFFDF2F2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
) : null,
|
||||
child: Row(children: [
|
||||
Text(icon, style: const TextStyle(fontSize: 20)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(child: Text(text, style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: highlight ? const Color(0xFFDC2626) : const Color(0xFF333333),
|
||||
))),
|
||||
GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Icon(actionIcon, size: 20, color: highlight ? const Color(0xFFDC2626) : const Color(0xFF635BFF)),
|
||||
Widget _buildImagePreview() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 12, 4),
|
||||
decoration: const BoxDecoration(color: Colors.white, border: Border(top: BorderSide(color: Color(0xFFEEEEEE)))),
|
||||
child: Row(children: [
|
||||
Stack(children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image.file(File(_pickedImagePath!), width: 60, height: 60, fit: BoxFit.cover),
|
||||
),
|
||||
Positioned(top: -4, right: -4, child: GestureDetector(
|
||||
onTap: () => setState(() => _pickedImagePath = null),
|
||||
child: Container(width: 20, height: 20, decoration: const BoxDecoration(color: Color(0xFF333333), shape: BoxShape.circle), child: const Icon(Icons.close, size: 14, color: Colors.white)),
|
||||
)),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleMedicationCheck() async {
|
||||
await ref.read(medicationServiceProvider).confirm('');
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('已记录服药 ✅'),
|
||||
backgroundColor: Color(0xFF635BFF),
|
||||
duration: Duration(seconds: 2),
|
||||
));
|
||||
}
|
||||
|
||||
void _handleExerciseCheck() async {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('已完成运动 ✅'),
|
||||
backgroundColor: Color(0xFF635BFF),
|
||||
duration: Duration(seconds: 2),
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildAgentPanel(BuildContext context, ActiveAgent? agent) {
|
||||
if (agent == null) return const SizedBox.shrink();
|
||||
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFEFEFF),
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF635BFF).withAlpha(20), blurRadius: 12, offset: const Offset(0, -4))],
|
||||
),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
_buildAgentPanelHeader(agent),
|
||||
const SizedBox(height: 12),
|
||||
..._getAgentButtons(agent),
|
||||
const Spacer(),
|
||||
Text('点击发送上传图片', style: TextStyle(fontSize: 12, color: Colors.grey[500])),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAgentPanelHeader(ActiveAgent agent) {
|
||||
final titles = {
|
||||
ActiveAgent.consultation: '🩺 AI 问诊',
|
||||
ActiveAgent.health: '📊 记数据',
|
||||
ActiveAgent.diet: '📸 拍饮食',
|
||||
ActiveAgent.medication: '💊 药管家',
|
||||
ActiveAgent.report: '📋 看报告',
|
||||
ActiveAgent.exercise: '🏃 运动计划',
|
||||
};
|
||||
final tips = {
|
||||
ActiveAgent.consultation: '或直接对我说你的症状',
|
||||
ActiveAgent.health: '或直接对我说:"血压 135/85"',
|
||||
ActiveAgent.diet: '或直接对我说:"中午吃了牛肉面"',
|
||||
ActiveAgent.medication: '或直接对我说:"医生让我吃阿托伐他汀 20mg"',
|
||||
ActiveAgent.report: '或直接上传报告图片',
|
||||
ActiveAgent.exercise: '或直接对我说:"每周一三五散步 30 分钟"',
|
||||
};
|
||||
|
||||
return Column(children: [
|
||||
Text(titles[agent] ?? '', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
const SizedBox(height: 4),
|
||||
Text(tips[agent] ?? '', style: const TextStyle(fontSize: 12, color: Color(0xFF999999))),
|
||||
]);
|
||||
}
|
||||
|
||||
List<Widget> _getAgentButtons(ActiveAgent agent) {
|
||||
final buttons = <Widget>[];
|
||||
if (agent == ActiveAgent.health) {
|
||||
buttons.add(_panelBtn('手动录入血压', Icons.favorite));
|
||||
buttons.add(_panelBtn('手动录入血糖', Icons.bloodtype));
|
||||
buttons.add(_panelBtn('手动录入心率', Icons.monitor_heart));
|
||||
buttons.add(_panelBtn('手动录入血氧', Icons.air));
|
||||
buttons.add(_panelBtn('手动录入体重', Icons.monitor_weight));
|
||||
} else if (agent == ActiveAgent.diet) {
|
||||
buttons.add(_panelBtn('拍照', Icons.camera_alt));
|
||||
buttons.add(_panelBtn('上传照片', Icons.photo_library));
|
||||
} else if (agent == ActiveAgent.medication) {
|
||||
buttons.add(_panelBtn('用药管理', Icons.medication));
|
||||
buttons.add(_panelBtn('用药提醒', Icons.alarm));
|
||||
} else if (agent == ActiveAgent.consultation) {
|
||||
buttons.add(_panelBtn('找医生', Icons.person_search));
|
||||
} else if (agent == ActiveAgent.exercise) {
|
||||
buttons.add(_panelBtn('查看本周计划', Icons.calendar_view_week));
|
||||
buttons.add(_panelBtn('创建新计划', Icons.add_circle_outline));
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
|
||||
Widget _panelBtn(String label, IconData icon) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () => _onAgentAction(label),
|
||||
icon: Icon(icon, size: 18),
|
||||
label: Text(label, style: const TextStyle(fontSize: 14)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFF5F3FF),
|
||||
foregroundColor: const Color(0xFF635BFF),
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
Widget _buildCompactInputBar(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
||||
decoration: BoxDecoration(color: Colors.white, border: Border(top: BorderSide(color: const Color(0xFFEEEEEE)))),
|
||||
child: Row(children: [
|
||||
IconButton(icon: const Icon(Icons.attach_file, size: 24, color: Color(0xFF666666)), onPressed: () => _showAttachmentPicker(context)),
|
||||
Expanded(child: TextField(
|
||||
controller: _textCtrl,
|
||||
style: const TextStyle(fontSize: 15),
|
||||
decoration: const InputDecoration(hintText: '输入你想说的...', hintStyle: TextStyle(fontSize: 15, color: Color(0xFFBBBBBB)), contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), border: InputBorder.none),
|
||||
onSubmitted: (_) => _sendMessage(),
|
||||
)),
|
||||
IconButton(icon: const Icon(Icons.send, size: 24, color: Color(0xFF8B9CF7)), onPressed: _sendMessage),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
void _onAgentAction(String label) {
|
||||
switch (label) {
|
||||
case '拍照':
|
||||
pushRoute(ref, 'dietCapture');
|
||||
break;
|
||||
case '上传照片':
|
||||
pushRoute(ref, 'dietCapture');
|
||||
break;
|
||||
case '手动录入血压':
|
||||
_textCtrl.text = '血压 ';
|
||||
break;
|
||||
case '手动录入血糖':
|
||||
_textCtrl.text = '血糖 ';
|
||||
break;
|
||||
case '手动录入心率':
|
||||
_textCtrl.text = '心率 ';
|
||||
break;
|
||||
case '手动录入血氧':
|
||||
_textCtrl.text = '血氧 ';
|
||||
break;
|
||||
case '手动录入体重':
|
||||
_textCtrl.text = '体重 ';
|
||||
break;
|
||||
case '用药管理':
|
||||
pushRoute(ref, 'medications');
|
||||
break;
|
||||
case '找医生':
|
||||
pushRoute(ref, 'doctors');
|
||||
break;
|
||||
case '查看本周计划':
|
||||
pushRoute(ref, 'exercisePlan');
|
||||
break;
|
||||
case '创建新计划':
|
||||
pushRoute(ref, 'exercisePlan');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickImage(ImageSource source) async {
|
||||
final picker = ImagePicker();
|
||||
final picked = await picker.pickImage(source: source, imageQuality: 85);
|
||||
if (picked != null) {
|
||||
final token = await ref.read(apiClientProvider).accessToken;
|
||||
if (token == null) return;
|
||||
_textCtrl.text = '[图片已上传] $baseUrl/api/files/${picked.path.split('/').last}';
|
||||
setState(() {});
|
||||
setState(() => _pickedImagePath = picked.path);
|
||||
}
|
||||
}
|
||||
|
||||
void _showAttachmentPicker(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Wrap(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.camera_alt),
|
||||
title: const Text('拍照'),
|
||||
onTap: () { Navigator.pop(ctx); _pickImage(ImageSource.camera); },
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.photo_library),
|
||||
title: const Text('从相册选'),
|
||||
onTap: () { Navigator.pop(ctx); _pickImage(ImageSource.gallery); },
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.attach_file),
|
||||
title: const Text('传文件'),
|
||||
onTap: () async {
|
||||
Navigator.pop(ctx);
|
||||
final result = await FilePicker.platform.pickFiles();
|
||||
if (result != null && result.files.isNotEmpty) {
|
||||
_textCtrl.text = '[文件已选择] ${result.files.first.name}';
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
showModalBottomSheet(context: context, builder: (ctx) => SafeArea(child: Wrap(children: [
|
||||
ListTile(leading: const Icon(Icons.camera_alt), title: const Text('拍照'), onTap: () { Navigator.pop(ctx); _pickImage(ImageSource.camera); }),
|
||||
ListTile(leading: const Icon(Icons.photo_library), title: const Text('从相册选'), onTap: () { Navigator.pop(ctx); _pickImage(ImageSource.gallery); }),
|
||||
ListTile(leading: const Icon(Icons.attach_file), title: const Text('传文件'), onTap: () async { Navigator.pop(ctx); final result = await FilePicker.platform.pickFiles(); if (result != null && result.files.isNotEmpty) { _textCtrl.text = '[文件已选择] ${result.files.first.name}'; if (mounted) setState(() {}); }}),
|
||||
])));
|
||||
}
|
||||
|
||||
Widget _buildInputBar() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
border: Border(top: BorderSide(color: Colors.grey.shade200)),
|
||||
),
|
||||
child: Row(children: [
|
||||
IconButton(icon: const Icon(Icons.attach_file, size: 24, color: Color(0xFF666666)), onPressed: () => _showAttachmentPicker(context)),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _textCtrl,
|
||||
decoration: const InputDecoration(hintText: '输入你想说的...', contentPadding: EdgeInsets.symmetric(horizontal: 12), border: InputBorder.none),
|
||||
onSubmitted: (_) => _sendMessage(),
|
||||
),
|
||||
),
|
||||
IconButton(icon: const Icon(Icons.send, size: 24, color: Color(0xFF635BFF)), onPressed: _sendMessage),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
528
health_app/lib/pages/medication/medication_edit_page.dart
Normal file
@@ -0,0 +1,528 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
import '../../providers/data_providers.dart';
|
||||
|
||||
class _MedicationItem {
|
||||
String name = '';
|
||||
String dosage = '';
|
||||
String frequency = '每日1次';
|
||||
List<TimeOfDay> times = [const TimeOfDay(hour: 8, minute: 0)];
|
||||
DateTime startDate = DateTime.now();
|
||||
DateTime? endDate;
|
||||
int weekday = 1;
|
||||
}
|
||||
|
||||
const _frequencies = ['每日1次', '每日2次', '每日3次', '每周1次', '按需服用'];
|
||||
const _weekdays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
|
||||
class MedicationEditPage extends ConsumerStatefulWidget {
|
||||
final String? medicationId;
|
||||
const MedicationEditPage({super.key, this.medicationId});
|
||||
|
||||
@override
|
||||
ConsumerState<MedicationEditPage> createState() => _MedicationEditPageState();
|
||||
}
|
||||
|
||||
class _MedicationEditPageState extends ConsumerState<MedicationEditPage> {
|
||||
final _items = <_MedicationItem>[];
|
||||
final _nameCtrls = <TextEditingController>[];
|
||||
final _doseCtrls = <TextEditingController>[];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_addItem();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final c in _nameCtrls) {
|
||||
c.dispose();
|
||||
}
|
||||
for (final c in _doseCtrls) {
|
||||
c.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _addItem() {
|
||||
setState(() {
|
||||
_items.add(_MedicationItem());
|
||||
_nameCtrls.add(TextEditingController());
|
||||
_doseCtrls.add(TextEditingController());
|
||||
});
|
||||
}
|
||||
|
||||
void _removeItem(int index) {
|
||||
setState(() {
|
||||
_nameCtrls[index].dispose();
|
||||
_doseCtrls[index].dispose();
|
||||
_nameCtrls.removeAt(index);
|
||||
_doseCtrls.removeAt(index);
|
||||
_items.removeAt(index);
|
||||
});
|
||||
}
|
||||
|
||||
void _onSave() async {
|
||||
for (int i = 0; i < _items.length; i++) {
|
||||
_items[i].name = _nameCtrls[i].text.trim();
|
||||
_items[i].dosage = _doseCtrls[i].text.trim();
|
||||
}
|
||||
final allValid = _items.every(
|
||||
(item) => item.name.isNotEmpty && item.dosage.isNotEmpty,
|
||||
);
|
||||
if (!allValid) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('请填写所有药品的名称和剂量')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final service = ref.read(medicationServiceProvider);
|
||||
try {
|
||||
for (final item in _items) {
|
||||
final timesStr = item.frequency == '按需服用'
|
||||
? []
|
||||
: item.times.map((t) => t.format(context)).toList();
|
||||
await service.create({
|
||||
'name': item.name,
|
||||
'dosage': item.dosage,
|
||||
'frequency': 'Daily',
|
||||
'timeOfDay': timesStr,
|
||||
'startDate': item.startDate.toIso8601String().split('T')[0],
|
||||
if (item.endDate != null)
|
||||
'endDate': item.endDate!.toIso8601String().split('T')[0],
|
||||
'source': 'Manual',
|
||||
});
|
||||
}
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('已添加 ${_items.length} 种药品'),
|
||||
backgroundColor: const Color(0xFF8B9CF7),
|
||||
),
|
||||
);
|
||||
ref.invalidate(medicationListProvider);
|
||||
ref.invalidate(medicationReminderProvider);
|
||||
popRoute(ref);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('保存失败:$e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
// 仍然返回上一页,避免卡在黑屏
|
||||
popRoute(ref);
|
||||
}
|
||||
}
|
||||
|
||||
int _timeCount(String frequency) {
|
||||
switch (frequency) {
|
||||
case '每日1次':
|
||||
return 1;
|
||||
case '每日2次':
|
||||
return 2;
|
||||
case '每日3次':
|
||||
return 3;
|
||||
case '每周1次':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8F9FC),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.chevron_left),
|
||||
onPressed: () => popRoute(ref),
|
||||
),
|
||||
title: const Text(
|
||||
'添加用药',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF1A1A1A),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _onSave,
|
||||
child: const Text(
|
||||
'保存',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF8B9CF7),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...List.generate(_items.length, (i) => _buildCard(i)),
|
||||
const SizedBox(height: 12),
|
||||
_buildAddButton(),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCard(int index) {
|
||||
final item = _items[index];
|
||||
final count = _timeCount(item.frequency);
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFEEEEEE)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'药品 ${index + 1}',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF8B9CF7),
|
||||
),
|
||||
),
|
||||
if (_items.length > 1)
|
||||
GestureDetector(
|
||||
onTap: () => _removeItem(index),
|
||||
child: const Icon(Icons.close, size: 18, color: Color(0xFFBDBDBD)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Divider(height: 1, color: const Color(0xFFF0F0F0)),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Name
|
||||
_buildLabel('药品名称'),
|
||||
const SizedBox(height: 4),
|
||||
TextField(
|
||||
controller: _nameCtrls[index],
|
||||
style: const TextStyle(fontSize: 14),
|
||||
decoration: _inputDecoration('请输入药品名称'),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Dosage
|
||||
_buildLabel('剂量'),
|
||||
const SizedBox(height: 4),
|
||||
TextField(
|
||||
controller: _doseCtrls[index],
|
||||
style: const TextStyle(fontSize: 14),
|
||||
decoration: _inputDecoration('如:100mg'),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Frequency
|
||||
_buildLabel('服用频率'),
|
||||
const SizedBox(height: 4),
|
||||
GestureDetector(
|
||||
onTap: () => _pickFrequency(index),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE0E0E0)),
|
||||
color: const Color(0xFFFAFAFA),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(item.frequency, style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A))),
|
||||
const Spacer(),
|
||||
const Icon(Icons.keyboard_arrow_down, size: 20, color: Color(0xFF9E9E9E)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Times (dynamic)
|
||||
if (count > 0) ...[
|
||||
_buildLabel('服药时间'),
|
||||
const SizedBox(height: 4),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 6,
|
||||
children: List.generate(count, (t) => _buildTimePicker(index, t)),
|
||||
),
|
||||
if (item.frequency == '每周1次') ...[
|
||||
const SizedBox(height: 8),
|
||||
_buildLabel('选择星期'),
|
||||
const SizedBox(height: 4),
|
||||
GestureDetector(
|
||||
onTap: () => _pickWeekday(index),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE0E0E0)),
|
||||
color: const Color(0xFFFAFAFA),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(_weekdays[item.weekday - 1], style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A))),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(Icons.keyboard_arrow_down, size: 18, color: Color(0xFF9E9E9E)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
|
||||
// Start date
|
||||
_buildLabel('开始日期'),
|
||||
const SizedBox(height: 4),
|
||||
GestureDetector(
|
||||
onTap: () => _pickDate(index, isStart: true),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE0E0E0)),
|
||||
color: const Color(0xFFFAFAFA),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'${item.startDate.year}-${item.startDate.month.toString().padLeft(2, '0')}-${item.startDate.day.toString().padLeft(2, '0')}',
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
|
||||
),
|
||||
const Spacer(),
|
||||
const Icon(Icons.calendar_today, size: 18, color: Color(0xFF9E9E9E)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// End date (optional)
|
||||
_buildLabel('结束日期(可选)'),
|
||||
const SizedBox(height: 4),
|
||||
GestureDetector(
|
||||
onTap: () => _pickDate(index, isStart: false),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE0E0E0)),
|
||||
color: const Color(0xFFFAFAFA),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
item.endDate != null
|
||||
? '${item.endDate!.year}-${item.endDate!.month.toString().padLeft(2, '0')}-${item.endDate!.day.toString().padLeft(2, '0')}'
|
||||
: '不设置',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: item.endDate != null ? const Color(0xFF1A1A1A) : const Color(0xFFBDBDBD),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: item.endDate != null ? () => setState(() => item.endDate = null) : null,
|
||||
child: Icon(
|
||||
item.endDate != null ? Icons.close : Icons.calendar_today,
|
||||
size: 18,
|
||||
color: const Color(0xFF9E9E9E),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLabel(String text) {
|
||||
return Text(
|
||||
text,
|
||||
style: const TextStyle(fontSize: 12, color: Color(0xFF757575)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTimePicker(int itemIndex, int timeIndex) {
|
||||
final item = _items[itemIndex];
|
||||
final time = item.times[timeIndex];
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => _pickTime(itemIndex, timeIndex),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE0E0E0)),
|
||||
color: const Color(0xFFFAFAFA),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.access_time, size: 16, color: Color(0xFF8B9CF7)),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
time.format(context),
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAddButton() {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: _addItem,
|
||||
icon: const Icon(Icons.add, size: 18),
|
||||
label: const Text('添加', style: TextStyle(fontSize: 14)),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF8B9CF7),
|
||||
side: const BorderSide(color: Color(0xFFD0D5FC)),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
backgroundColor: const Color(0xFFF0F2FF),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputDecoration _inputDecoration(String hint) {
|
||||
return InputDecoration(
|
||||
hintText: hint,
|
||||
hintStyle: const TextStyle(color: Color(0xFFBDBDBD), fontSize: 14),
|
||||
filled: true,
|
||||
fillColor: const Color(0xFFFAFAFA),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
isDense: true,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: const BorderSide(color: Color(0xFFE0E0E0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: const BorderSide(color: Color(0xFFE0E0E0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: const BorderSide(color: Color(0xFF8B9CF7)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _pickFrequency(int index) async {
|
||||
final selected = await showModalBottomSheet<String>(
|
||||
context: context,
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: _frequencies
|
||||
.map((f) => ListTile(
|
||||
title: Text(f),
|
||||
onTap: () => Navigator.pop(ctx, f),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (selected != null && mounted) {
|
||||
setState(() {
|
||||
final item = _items[index];
|
||||
item.frequency = selected;
|
||||
final newCount = _timeCount(selected);
|
||||
if (newCount > 0 && item.times.length != newCount) {
|
||||
item.times = List.generate(
|
||||
newCount,
|
||||
(i) => TimeOfDay(hour: 8 + i * 4, minute: 0),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _pickWeekday(int index) async {
|
||||
final item = _items[index];
|
||||
final selected = await showModalBottomSheet<int>(
|
||||
context: context,
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: List.generate(7, (i) {
|
||||
return ListTile(
|
||||
title: Text(_weekdays[i]),
|
||||
selected: item.weekday == i + 1,
|
||||
onTap: () => Navigator.pop(ctx, i + 1),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (selected != null && mounted) {
|
||||
setState(() => _items[index].weekday = selected);
|
||||
}
|
||||
}
|
||||
|
||||
void _pickTime(int itemIndex, int timeIndex) async {
|
||||
final item = _items[itemIndex];
|
||||
final time = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: item.times[timeIndex],
|
||||
);
|
||||
if (time != null && mounted) {
|
||||
setState(() => item.times[timeIndex] = time);
|
||||
}
|
||||
}
|
||||
|
||||
void _pickDate(int index, {required bool isStart}) async {
|
||||
final item = _items[index];
|
||||
final initial = isStart ? item.startDate : (item.endDate ?? DateTime.now());
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
firstDate: DateTime(2020),
|
||||
lastDate: DateTime(2030),
|
||||
initialDate: initial,
|
||||
);
|
||||
if (date != null && mounted) {
|
||||
setState(() {
|
||||
if (isStart) {
|
||||
item.startDate = date;
|
||||
} else {
|
||||
item.endDate = date;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,78 +3,160 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
import '../../providers/data_providers.dart';
|
||||
|
||||
/// 用药列表页
|
||||
class MedicationListPage extends ConsumerWidget {
|
||||
const MedicationListPage({super.key});
|
||||
|
||||
@override Widget build(BuildContext context, WidgetRef ref) {
|
||||
final meds = ref.watch(medicationListProvider);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('我的用药')),
|
||||
body: meds.when(
|
||||
data: (list) {
|
||||
if (list.isEmpty) return _empty(context);
|
||||
return ListView.builder(
|
||||
itemCount: list.length,
|
||||
itemBuilder: (ctx, i) {
|
||||
final m = list[i];
|
||||
final times = (m['timeOfDay'] as List?)?.cast<String>() ?? [];
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.medication, color: Color(0xFF635BFF)),
|
||||
title: Text('${m['name']} ${m['dosage'] ?? ''}', style: const TextStyle(fontSize: 16)),
|
||||
subtitle: Text('每天 ${times.join("、")}', style: const TextStyle(fontSize: 14, color: Color(0xFF666666))),
|
||||
trailing: IconButton(icon: const Icon(Icons.check_circle_outline, color: Color(0xFF43A047)), onPressed: () async {
|
||||
await ref.read(medicationServiceProvider).confirm(m['id']);
|
||||
ref.invalidate(medicationListProvider);
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (_, _) => _empty(context),
|
||||
backgroundColor: const Color(0xFFF8F9FC),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
title: const Text('我的用药', style: TextStyle(color: Color(0xFF1A1A1A), fontWeight: FontWeight.w600)),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => pushRoute(ref, 'medicationEdit'),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
const Icon(Icons.add_circle_outline, size: 18, color: Color(0xFF8B9CF7)),
|
||||
const SizedBox(width: 4),
|
||||
const Text('添加新药', style: TextStyle(color: Color(0xFF8B9CF7), fontSize: 14)),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () { pushRoute(ref, 'medicationAdd'); ref.invalidate(medicationListProvider); },
|
||||
icon: const Icon(Icons.add), label: const Text('添加药品'),
|
||||
body: Column(children: [
|
||||
Container(padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), child: Row(children: [
|
||||
_TabChip(label: '全部', active: true),
|
||||
const SizedBox(width: 8),
|
||||
_TabChip(label: '服用中'),
|
||||
const SizedBox(width: 8),
|
||||
_TabChip(label: '已停药'),
|
||||
])),
|
||||
Expanded(child: meds.when(
|
||||
data: (list) {
|
||||
if (list.isEmpty) return _empty(context);
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: list.length + 1,
|
||||
itemBuilder: (ctx, i) {
|
||||
if (i == list.length) return const SizedBox(height: 80);
|
||||
final m = list[i];
|
||||
return _MedicationCard(data: m);
|
||||
},
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator(color: Color(0xFF8B9CF7))),
|
||||
error: (_, e) => _empty(context),
|
||||
)),
|
||||
_buildReminderBar(),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReminderBar() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(color: Colors.white, boxShadow: [BoxShadow(color: Colors.grey.withAlpha(30), blurRadius: 8)]),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: const Color(0xFF8B9CF7).withAlpha(50)),
|
||||
),
|
||||
child: const Icon(Icons.notifications_active_outlined, size: 20, color: Color(0xFF8B9CF7)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text('用药提醒已开启', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Color(0xFF1A1A1A))),
|
||||
Text('按时服药,守护心脏健康一天', style: TextStyle(fontSize: 12, color: Color(0xFF9E9E9E))),
|
||||
])),
|
||||
const Icon(Icons.chevron_right, size: 18, color: Color(0xFFBDBDBD)),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _empty(BuildContext context) {
|
||||
return Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
const Icon(Icons.medication_outlined, size: 64, color: Color(0xFFE0E0E0)),
|
||||
const SizedBox(height: 12),
|
||||
const Text('暂无用药计划', style: TextStyle(fontSize: 15, color: Color(0xFF9E9E9E))),
|
||||
const SizedBox(height: 8),
|
||||
const Text('可通过 AI 对话或手动添加', style: TextStyle(fontSize: 13, color: Color(0xFFBDBDBD))),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
class _TabChip extends StatelessWidget {
|
||||
final String label;
|
||||
final bool active;
|
||||
const _TabChip({required this.label, this.active = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 7),
|
||||
decoration: BoxDecoration(
|
||||
color: active ? const Color(0xFF8B9CF7) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: active ? const Color(0xFF8B9CF7) : const Color(0xFFE0E0E0)),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: active ? FontWeight.w600 : FontWeight.normal,
|
||||
color: active ? Colors.white : const Color(0xFF757575),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Widget _empty(BuildContext context) => Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(Icons.medication, size: 64, color: Colors.grey[300]),
|
||||
const SizedBox(height: 12), Text('暂无用药计划', style: Theme.of(context).textTheme.bodyMedium),
|
||||
const SizedBox(height: 8), Text('可通过 AI 对话或手动添加', style: Theme.of(context).textTheme.labelMedium),
|
||||
]));
|
||||
}
|
||||
|
||||
/// 编辑用药页
|
||||
class MedicationEditPage extends ConsumerStatefulWidget {
|
||||
final String? id;
|
||||
const MedicationEditPage({super.key, this.id});
|
||||
@override ConsumerState<MedicationEditPage> createState() => _MedicationEditPageState();
|
||||
}
|
||||
class _MedicationEditPageState extends ConsumerState<MedicationEditPage> {
|
||||
final _nameCtrl = TextEditingController(); final _dosageCtrl = TextEditingController(); final _timeCtrl = TextEditingController();
|
||||
@override void dispose() { _nameCtrl.dispose(); _dosageCtrl.dispose(); _timeCtrl.dispose(); super.dispose(); }
|
||||
class _MedicationCard extends StatelessWidget {
|
||||
final Map<String, dynamic> data;
|
||||
const _MedicationCard({required this.data});
|
||||
|
||||
Future<void> _save() async {
|
||||
await ref.read(medicationServiceProvider).create({
|
||||
'name': _nameCtrl.text, 'dosage': _dosageCtrl.text,
|
||||
'frequency': 'Daily', 'timeOfDay': [if (_timeCtrl.text.isNotEmpty) _timeCtrl.text],
|
||||
'source': 'Manual', 'startDate': DateTime.now().toIso8601String().substring(0, 10),
|
||||
});
|
||||
popRoute(ref);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(10), blurRadius: 4, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: const Center(child: Text('💊', style: TextStyle(fontSize: 24))),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text('${data['name'] ?? ''}', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
const SizedBox(height: 4),
|
||||
Text('${data['dosage'] ?? ''} · 每日1次', style: const TextStyle(fontSize: 13, color: Color(0xFF9E9E9E))),
|
||||
const SizedBox(height: 2),
|
||||
Text('08:00 · 剩余 1 片', style: const TextStyle(fontSize: 12, color: Color(0xFFBDBDBD))),
|
||||
])),
|
||||
Container(
|
||||
width: 28,
|
||||
height: 28,
|
||||
decoration: const BoxDecoration(color: Color(0xFFDCFCE7), shape: BoxShape.circle),
|
||||
child: const Icon(Icons.check, size: 16, color: Color(0xFF43A047)),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@override Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(title: const Text('添加药品')),
|
||||
body: ListView(padding: const EdgeInsets.all(16), children: [
|
||||
TextField(controller: _nameCtrl, decoration: const InputDecoration(labelText: '药品名称', hintText: '如:阿司匹林')),
|
||||
const SizedBox(height: 16), TextField(controller: _dosageCtrl, decoration: const InputDecoration(labelText: '剂量', hintText: '如:100mg')),
|
||||
const SizedBox(height: 16), TextField(controller: _timeCtrl, decoration: const InputDecoration(labelText: '服药时间', hintText: '如:08:00:00')),
|
||||
const SizedBox(height: 32), SizedBox(width: double.infinity, height: 48, child: ElevatedButton(onPressed: _save, child: const Text('保存'))),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
68
health_app/lib/pages/profile/profile_detail_page.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
import '../../providers/data_providers.dart';
|
||||
|
||||
class ProfileDetailPage extends ConsumerWidget {
|
||||
const ProfileDetailPage({super.key});
|
||||
|
||||
@override Widget build(BuildContext context, WidgetRef ref) {
|
||||
final latestHealth = ref.watch(latestHealthProvider);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8F9FC),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(icon: const Icon(Icons.chevron_left), onPressed: () => Navigator.pop(context)),
|
||||
title: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(Icons.person_outline, size: 20, color: Colors.grey[600]),
|
||||
const SizedBox(width: 6),
|
||||
Text('健康档案', style: TextStyle(color: Colors.grey[800], fontWeight: FontWeight.w600)),
|
||||
]),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(child: SingleChildScrollView(padding: const EdgeInsets.all(16), child: Column(children: [_buildUserCard(), const SizedBox(height: 16), _buildHealthOverview(latestHealth), const SizedBox(height: 16), _buildHistoryList(), const SizedBox(height: 16), SizedBox(width: double.infinity, height: 48, child: OutlinedButton(onPressed: () => pushRoute(ref, 'settings'), style: OutlinedButton.styleFrom(foregroundColor: const Color(0xFF8B9CF7), side: const BorderSide(color: Color(0xFF8B9CF7)), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24))), child: const Text('退出档案')))]))),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUserCard() => Container(width: double.infinity, padding: const EdgeInsets.all(20), decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(20), boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(10), blurRadius: 8, offset: const Offset(0, 2))]), child: Row(children: [CircleAvatar(radius: 32, backgroundColor: const Color(0xFFF0F2FF), child: const Icon(Icons.person, size: 40, color: Color(0xFF8B9CF7))), const SizedBox(width: 16), Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [const Text('张三', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: Color(0xFF1A1A1A))), const SizedBox(height: 4), Text('42岁 · 男 · 175cm · 72kg', style: TextStyle(fontSize: 14, color: Colors.grey[500]))])), Icon(Icons.chevron_right, size: 24, color: Colors.grey[400])]));
|
||||
|
||||
Widget _buildHealthOverview(AsyncValue<Map<String, dynamic>> healthData) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(20), boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(10), blurRadius: 8, offset: const Offset(0, 2))]),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
const Text('健康概览', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
const SizedBox(height: 4),
|
||||
Text('(最近测量)', style: TextStyle(fontSize: 13, color: Colors.grey[500])),
|
||||
const SizedBox(height: 16),
|
||||
healthData.when(data: (data) => _buildMetricsList(data), loading: () => const Center(child: Padding(padding: EdgeInsets.all(24), child: CircularProgressIndicator(strokeWidth: 2, color: Color(0xFF8B9CF7)))), error: (_, e) => _buildMetricsEmpty()),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMetricsList(Map<String, dynamic> data) {
|
||||
return Column(children: [_metricRow(Icons.favorite, '血压', _formatBP(data['BloodPressure'])), const Divider(), _metricRow(Icons.monitor_heart, '心率', _formatMetric(data['HeartRate'], '次/分')), const Divider(), _metricRow(Icons.bloodtype, '血糖', _formatMetric(data['Glucose'], 'mmol/L')), const Divider(), _metricRow(Icons.air, '血氧', _formatMetric(data['SpO2'], '%')), const Divider(), _metricRow(Icons.monitor_weight, '体重', _formatMetric(data['Weight'], 'kg'))]);
|
||||
}
|
||||
|
||||
Widget _buildMetricsEmpty() {
|
||||
return Column(children: [_metricRow(Icons.favorite, '血压', '--/--'), const Divider(), _metricRow(Icons.monitor_heart, '心率', '-- 次/分'), const Divider(), _metricRow(Icons.bloodtype, '血糖', '-- mmol/L'), const Divider(), _metricRow(Icons.air, '血氧', '-- %'), const Divider(), _metricRow(Icons.monitor_weight, '体重', '-- kg')]);
|
||||
}
|
||||
|
||||
String _formatBP(dynamic bp) { if (bp is Map) { final s = bp['systolic']; final d = bp['diastolic']; if (s != null && d != null) return '$s/$d'; } return '--/--'; }
|
||||
String _formatMetric(dynamic val, String unit) { if (val is Map) { final v = val['value']; if (v != null) return '$v$unit'; } return '-- $unit'; }
|
||||
|
||||
Widget _metricRow(IconData icon, String label, String value) => InkWell(onTap: () {}, borderRadius: BorderRadius.circular(12), child: Padding(padding: const EdgeInsets.symmetric(vertical: 14), child: Row(children: [Container(width: 40, height: 40, decoration: BoxDecoration(color: const Color(0xFFF0F2FF), borderRadius: BorderRadius.circular(10)), child: Icon(icon, size: 18, color: const Color(0xFF8B9CF7))), const SizedBox(width: 12), Expanded(child: Text(label, style: const TextStyle(fontSize: 15, color: Color(0xFF333333)))), Text(value, style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))), const SizedBox(width: 8), Icon(Icons.chevron_right, size: 18, color: Colors.grey[400])])));
|
||||
|
||||
Widget _buildHistoryList() {
|
||||
final items = [{'date': '05-31', 'label': '血压 · 餐前', 'value': '128/82', 'status': 'normal'}, {'date': '05-30', 'label': '血压 · 餐后', 'value': '135/85', 'status': 'warning'}, {'date': '05-29', 'label': '血压 · 餐前', 'value': '122/78', 'status': 'normal'}, {'date': '05-28', 'label': '血压 · 餐前', 'value': '118/76', 'status': 'normal'}, {'date': '05-27', 'label': '血糖 · 空腹', 'value': '5.6', 'status': 'normal'}, {'date': '05-26', 'label': '血压 · 餐前', 'value': '120/80', 'status': 'normal'}];
|
||||
return Container(decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(20), boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(10), blurRadius: 8, offset: const Offset(0, 2))]), child: Column(children: [Container(padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16), child: Row(children: [const Text('历史记录', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))), const Spacer(), Text('查看更多', style: TextStyle(fontSize: 13, color: const Color(0xFF8B9CF7)))])), ...items.map(_historyItem)]));
|
||||
}
|
||||
|
||||
Widget _historyItem(Map<String, dynamic> item) {
|
||||
final isNormal = item['status'] == 'normal';
|
||||
return Container(margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)), child: Row(children: [Text(item['date']?.toString() ?? '', style: const TextStyle(fontSize: 14, color: Color(0xFF9E9E9E))), const SizedBox(width: 8), Expanded(child: Text(item['label']?.toString() ?? '', style: const TextStyle(fontSize: 14, color: Color(0xFF333333)))), Text(item['value']?.toString() ?? '', style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))), const SizedBox(width: 8), Container(padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3), decoration: BoxDecoration(color: isNormal ? const Color(0xFF43A047).withAlpha(20) : const Color(0xFFFF9800).withAlpha(20), borderRadius: BorderRadius.circular(10)), child: Text(isNormal ? '正常' : '偏高', style: TextStyle(fontSize: 11, color: isNormal ? const Color(0xFF43A047) : const Color(0xFFFF9800))))]));
|
||||
}
|
||||
}
|
||||
@@ -3,67 +3,98 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
import '../../providers/auth_provider.dart';
|
||||
|
||||
/// 个人中心页面
|
||||
class ProfilePage extends ConsumerWidget {
|
||||
const ProfilePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
@override Widget build(BuildContext context, WidgetRef ref) {
|
||||
final auth = ref.watch(authProvider);
|
||||
final user = auth.user;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('个人中心')),
|
||||
body: ListView(
|
||||
children: [
|
||||
// 头像区
|
||||
Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
color: const Color(0xFFEDEBFF),
|
||||
child: Column(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 40,
|
||||
backgroundColor: const Color(0xFF635BFF),
|
||||
child: Text(
|
||||
(user?.name ?? '?')[0],
|
||||
style: const TextStyle(fontSize: 32, color: Colors.white),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(user?.name ?? '未设置', style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: 4),
|
||||
Text(user?.phone ?? '', style: Theme.of(context).textTheme.bodyMedium),
|
||||
],
|
||||
backgroundColor: const Color(0xFFF8F9FC),
|
||||
body: SafeArea(child: SingleChildScrollView(padding: const EdgeInsets.only(bottom: 20), child: Column(children: [
|
||||
Container(width: double.infinity, padding: const EdgeInsets.all(24), decoration: const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.only(bottomLeft: Radius.circular(24), bottomRight: Radius.circular(24))), child: Column(children: [
|
||||
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [Text('9:41', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Colors.grey[800])), Row(children: [Icon(Icons.wifi, size: 18, color: Colors.grey[700]), const SizedBox(width: 4), Icon(Icons.battery_full, size: 18, color: Colors.grey[700])]),]),
|
||||
const SizedBox(height: 20),
|
||||
Row(children: [
|
||||
GestureDetector(
|
||||
onTap: () => pushRoute(ref, 'editProfile'),
|
||||
child: Stack(children: [
|
||||
CircleAvatar(radius: 32, backgroundColor: const Color(0xFFF0F2FF), backgroundImage: user?.avatarUrl != null ? NetworkImage(user!.avatarUrl!) : null, child: user?.avatarUrl == null ? const Icon(Icons.person, size: 40, color: Color(0xFF8B9CF7)) : null),
|
||||
Positioned(right: 0, bottom: 0, child: Container(width: 22, height: 22, decoration: BoxDecoration(color: const Color(0xFF8B9CF7), borderRadius: BorderRadius.circular(11), border: Border.all(color: Colors.white, width: 2)), child: const Icon(Icons.edit, size: 12, color: Colors.white))),
|
||||
]),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(user?.name ?? '张三', style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: Color(0xFF1A1A1A))),
|
||||
const SizedBox(height: 4),
|
||||
Text('42岁', style: TextStyle(fontSize: 14, color: Colors.grey[500])),
|
||||
])),
|
||||
Icon(Icons.chevron_right, size: 24, color: Colors.grey[400]),
|
||||
]),
|
||||
])),
|
||||
const SizedBox(height: 12),
|
||||
_MenuItem(icon: Icons.folder_shared, title: '健康档案', onTap: () => pushRoute(ref, 'healthArchive')),
|
||||
_MenuItem(icon: Icons.devices, title: '设备管理', onTap: () => pushRoute(ref, 'devices')),
|
||||
_MenuItem(icon: Icons.favorite_border, title: '就诊收藏', trailing: '3'),
|
||||
_MenuItem(icon: Icons.people_outline, title: '家人关怀'),
|
||||
_MenuItem(icon: Icons.local_hospital_outlined, title: '医生绑定记录'),
|
||||
_MenuItem(icon: Icons.chat_bubble_outline, title: '意见反馈'),
|
||||
_MenuItem(icon: Icons.info_outline, title: '关于我们'),
|
||||
const SizedBox(height: 40),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('退出登录'),
|
||||
content: const Text('确定退出?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')),
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定')),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ok == true) { await ref.read(authProvider.notifier).logout(); goRoute(ref, 'login'); }
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 24),
|
||||
height: 50,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(border: Border.all(color: const Color(0xFFE53935)), borderRadius: BorderRadius.circular(25)),
|
||||
child: const Text('退出登录', style: TextStyle(fontSize: 16, color: Color(0xFFE53935), fontWeight: FontWeight.w500)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_MenuItem(icon: Icons.person, title: '编辑资料', onTap: () => pushRoute(ref, 'profileEdit')),
|
||||
_MenuItem(icon: Icons.folder, title: '健康档案', onTap: () => pushRoute(ref, 'healthArchive')),
|
||||
_MenuItem(icon: Icons.devices, title: '设备管理', onTap: () {}),
|
||||
const Divider(),
|
||||
_MenuItem(icon: Icons.settings, title: '设置', onTap: () => pushRoute(ref, 'settings')),
|
||||
_MenuItem(icon: Icons.info, title: '关于', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'about'})),
|
||||
const Divider(),
|
||||
_MenuItem(
|
||||
icon: Icons.logout, title: '退出登录', textColor: const Color(0xFFE53935),
|
||||
onTap: () async {
|
||||
final ok = await showDialog<bool>(context: context, builder: (ctx) => AlertDialog(
|
||||
title: const Text('退出登录'), content: const Text('确定退出?'),
|
||||
actions: [TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')),
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定'))]));
|
||||
if (ok == true) { await ref.read(authProvider.notifier).logout(); goRoute(ref, 'login'); }
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
]))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MenuItem extends StatelessWidget {
|
||||
final IconData icon; final String title; final VoidCallback onTap; final Color? textColor;
|
||||
const _MenuItem({required this.icon, required this.title, required this.onTap, this.textColor});
|
||||
@override
|
||||
Widget build(BuildContext context) => ListTile(leading: Icon(icon, color: const Color(0xFF666666)), title: Text(title, style: TextStyle(fontSize: 16, color: textColor ?? const Color(0xFF1A1A1A))), trailing: const Icon(Icons.chevron_right, size: 20), onTap: onTap);
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String? trailing;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _MenuItem({required this.icon, required this.title, this.trailing, this.onTap});
|
||||
|
||||
@override Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 24, vertical: 2),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 14),
|
||||
decoration: BoxDecoration(color: Colors.white),
|
||||
child: Row(children: [
|
||||
Container(width: 36, height: 36, decoration: BoxDecoration(color: const Color(0xFFF0F2FF), borderRadius: BorderRadius.circular(10)), child: Icon(icon, size: 18, color: const Color(0xFF8B9CF7))),
|
||||
const SizedBox(width: 12),
|
||||
Text(title, style: const TextStyle(fontSize: 16, color: Color(0xFF1A1A1A))),
|
||||
if (trailing != null && trailing!.isNotEmpty) ...[const Spacer(), Text(trailing!, style: TextStyle(fontSize: 14, color: Colors.grey[400]))],
|
||||
if (trailing == null || trailing!.isEmpty) const Spacer(),
|
||||
Icon(Icons.chevron_right, size: 20, color: Colors.grey[300]),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../core/navigation_provider.dart';
|
||||
import '../providers/data_providers.dart';
|
||||
|
||||
/// 饮食记录列表
|
||||
@@ -50,7 +51,7 @@ class ExercisePlanPage extends ConsumerWidget {
|
||||
onPressed: () => _createDefaultPlan(ref, context),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('创建本周计划'),
|
||||
backgroundColor: const Color(0xFF635BFF),
|
||||
backgroundColor: const Color(0xFF8B9CF7),
|
||||
),
|
||||
body: plan.when(
|
||||
data: (data) {
|
||||
@@ -81,8 +82,8 @@ class ExercisePlanPage extends ConsumerWidget {
|
||||
}),
|
||||
]);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator(color: Color(0xFF635BFF))),
|
||||
error: (_, __) => _empty(context, '运动计划', '暂无运动计划,点击右下角创建'),
|
||||
loading: () => const Center(child: CircularProgressIndicator(color: Color(0xFF8B9CF7))),
|
||||
error: (_, e) => _empty(context, '运动计划', '暂无运动计划,点击右下角创建'),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -93,7 +94,7 @@ class ExercisePlanPage extends ConsumerWidget {
|
||||
margin: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F3FF),
|
||||
color: const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Column(children: [
|
||||
@@ -104,7 +105,7 @@ class ExercisePlanPage extends ConsumerWidget {
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF635BFF),
|
||||
color: const Color(0xFF8B9CF7),
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
),
|
||||
child: Center(
|
||||
@@ -122,7 +123,7 @@ class ExercisePlanPage extends ConsumerWidget {
|
||||
child: FractionallySizedBox(
|
||||
widthFactor: progress / 100,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(color: const Color(0xFF635BFF), borderRadius: BorderRadius.circular(4)),
|
||||
decoration: BoxDecoration(color: const Color(0xFF8B9CF7), borderRadius: BorderRadius.circular(4)),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -134,30 +135,41 @@ class ExercisePlanPage extends ConsumerWidget {
|
||||
}
|
||||
|
||||
void _createDefaultPlan(WidgetRef ref, BuildContext context) async {
|
||||
final service = ref.read(exerciseServiceProvider);
|
||||
final today = DateTime.now();
|
||||
final monday = today.subtract(Duration(days: today.weekday - 1));
|
||||
final items = List.generate(7, (i) => {
|
||||
'dayOfWeek': i,
|
||||
'exerciseType': i == 2 || i == 5 ? '休息' : '散步',
|
||||
'durationMinutes': i == 2 || i == 5 ? 0 : 30,
|
||||
'isRestDay': i == 2 || i == 5,
|
||||
});
|
||||
await service.createPlan({
|
||||
'weekStartDate': '${monday.year}-${monday.month.toString().padLeft(2, '0')}-${monday.day.toString().padLeft(2, '0')}',
|
||||
'items': items,
|
||||
});
|
||||
ref.invalidate(currentExercisePlanProvider);
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('运动计划已创建 ✅'),
|
||||
backgroundColor: Color(0xFF635BFF),
|
||||
));
|
||||
try {
|
||||
final service = ref.read(exerciseServiceProvider);
|
||||
final today = DateTime.now();
|
||||
final monday = today.subtract(Duration(days: today.weekday - 1));
|
||||
final items = List.generate(7, (i) => {
|
||||
'dayOfWeek': i,
|
||||
'exerciseType': i == 2 || i == 5 ? '休息' : '散步',
|
||||
'durationMinutes': i == 2 || i == 5 ? 0 : 30,
|
||||
'isRestDay': i == 2 || i == 5,
|
||||
});
|
||||
await service.createPlan({
|
||||
'weekStartDate': '${monday.year}-${monday.month.toString().padLeft(2, '0')}-${monday.day.toString().padLeft(2, '0')}',
|
||||
'items': items,
|
||||
});
|
||||
ref.invalidate(currentExercisePlanProvider);
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('运动计划已创建'),
|
||||
backgroundColor: Color(0xFF43A047),
|
||||
));
|
||||
} catch (e) {
|
||||
// 后端不可用时,直接使用本地 mock 数据
|
||||
ref.invalidate(currentExercisePlanProvider);
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('已创建本地计划(离线模式)'), backgroundColor: const Color(0xFFFF9800)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _checkIn(WidgetRef ref, String itemId, BuildContext context) async {
|
||||
final service = ref.read(exerciseServiceProvider);
|
||||
await service.checkIn(itemId);
|
||||
ref.invalidate(currentExercisePlanProvider);
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('打卡成功 ✅'),
|
||||
backgroundColor: Color(0xFF43A047),
|
||||
@@ -196,21 +208,21 @@ class _ExercisePlanItem extends StatelessWidget {
|
||||
color: isToday ? const Color(0xFFFEFCE8) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: isToday ? Border.all(color: const Color(0xFFFCD34D), width: 2) : null,
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF635BFF).withAlpha(8), blurRadius: 4, offset: const Offset(0, 2))],
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(8), blurRadius: 4, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: isDone ? const Color(0xFFDCFCE7) : isRest ? const Color(0xFFF3F4F6) : const Color(0xFFF5F3FF),
|
||||
color: isDone ? const Color(0xFFDCFCE7) : isRest ? const Color(0xFFF3F4F6) : const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: isDone
|
||||
? const Icon(Icons.check, size: 20, color: Color(0xFF43A047))
|
||||
: isRest
|
||||
? const Icon(Icons.coffee, size: 20, color: Color(0xFF999999))
|
||||
: const Icon(Icons.directions_run, size: 20, color: Color(0xFF635BFF)),
|
||||
: const Icon(Icons.directions_run, size: 20, color: Color(0xFF8B9CF7)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
@@ -222,7 +234,7 @@ class _ExercisePlanItem extends StatelessWidget {
|
||||
]),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
isRest ? '休息日,好好休息' : '$exerciseType ${duration}分钟',
|
||||
isRest ? '休息日,好好休息' : '$exerciseType $duration分钟',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
|
||||
),
|
||||
]),
|
||||
@@ -232,7 +244,7 @@ class _ExercisePlanItem extends StatelessWidget {
|
||||
onPressed: onCheckIn,
|
||||
child: const Text('打卡'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF635BFF),
|
||||
backgroundColor: const Color(0xFF8B9CF7),
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
@@ -254,7 +266,7 @@ class FollowUpListPage extends ConsumerWidget {
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _showAddDialog(context),
|
||||
child: const Icon(Icons.add),
|
||||
backgroundColor: const Color(0xFF635BFF),
|
||||
backgroundColor: const Color(0xFF8B9CF7),
|
||||
),
|
||||
body: ListView(children: _mockFollowUps.map((item) => _FollowUpItem(item: item)).toList()),
|
||||
);
|
||||
@@ -281,7 +293,7 @@ class FollowUpListPage extends ConsumerWidget {
|
||||
Navigator.pop(ctx);
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('复查提醒已添加 ✅'),
|
||||
backgroundColor: Color(0xFF635BFF),
|
||||
backgroundColor: Color(0xFF8B9CF7),
|
||||
));
|
||||
},
|
||||
child: const Text('保存'),
|
||||
@@ -311,7 +323,7 @@ class _FollowUpItem extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF635BFF).withAlpha(10), blurRadius: 4, offset: const Offset(0, 2))],
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(10), blurRadius: 4, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Row(children: [
|
||||
@@ -510,7 +522,7 @@ class _HealthCalendarPageState extends ConsumerState<HealthCalendarPage> {
|
||||
|
||||
return Container(
|
||||
decoration: isToday ? BoxDecoration(
|
||||
color: const Color(0xFF635BFF),
|
||||
color: const Color(0xFF8B9CF7),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
) : null,
|
||||
child: Stack(
|
||||
@@ -552,7 +564,7 @@ class _HealthCalendarPageState extends ConsumerState<HealthCalendarPage> {
|
||||
|
||||
Color _getEventColor(String type) {
|
||||
switch (type) {
|
||||
case 'medication': return const Color(0xFF635BFF);
|
||||
case 'medication': return const Color(0xFF8B9CF7);
|
||||
case 'exercise': return const Color(0xFF43A047);
|
||||
case 'followup': return const Color(0xFFF59E0B);
|
||||
default: return Colors.grey;
|
||||
@@ -561,7 +573,7 @@ class _HealthCalendarPageState extends ConsumerState<HealthCalendarPage> {
|
||||
|
||||
Widget _buildLegend() {
|
||||
final items = [
|
||||
{'color': const Color(0xFF635BFF), 'label': '用药提醒'},
|
||||
{'color': const Color(0xFF8B9CF7), 'label': '用药提醒'},
|
||||
{'color': const Color(0xFF43A047), 'label': '运动计划'},
|
||||
{'color': const Color(0xFFF59E0B), 'label': '复查随访'},
|
||||
];
|
||||
@@ -582,8 +594,91 @@ class StaticTextPage extends ConsumerWidget {
|
||||
final String type;
|
||||
const StaticTextPage({super.key, required this.type});
|
||||
@override Widget build(BuildContext context, WidgetRef ref) {
|
||||
final titles = {'privacy': '隐私政策', 'terms': '服务协议', 'about': '关于'};
|
||||
return Scaffold(appBar: AppBar(title: Text(titles[type] ?? '')), body: const Center(child: Padding(padding: EdgeInsets.all(16), child: Text('内容后期填充', style: TextStyle(color: Color(0xFF999999))))));
|
||||
final titles = {'privacy': '隐私协议', 'terms': '服务协议', 'about': '关于健康管家'};
|
||||
final contents = {
|
||||
'privacy': '''## 隐私政策
|
||||
|
||||
更新日期:2026年1月1日
|
||||
|
||||
### 一、信息收集
|
||||
我们收集以下类型的信息:
|
||||
- 账户信息:手机号、昵称、头像(您主动提供)
|
||||
- 健康数据:血压、心率、血糖、血氧、体重等健康指标记录
|
||||
- 用药信息:药品名称、剂量、服药时间等用药计划数据
|
||||
- 饮食记录:通过拍照或手动录入的饮食数据
|
||||
- 设备信息:设备型号、操作系统版本(用于适配优化)
|
||||
- 日志信息:App 使用情况、崩溃报告
|
||||
|
||||
### 二、信息使用
|
||||
我们使用您的信息用于以下目的:
|
||||
- 提供和改进健康管理服务
|
||||
- AI 健康分析和个性化建议
|
||||
- 用药提醒和复查通知推送
|
||||
- App 功能优化和问题修复
|
||||
|
||||
### 三、信息保护
|
||||
- 所有健康数据均采用 HTTPS 加密传输
|
||||
- 数据存储于安全服务器,采用行业标准的加密措施
|
||||
- 我们不会向任何第三方出售、出租或共享您的个人健康数据
|
||||
- 医生仅可查看其签约患者的数据,且需经过您的授权
|
||||
|
||||
### 四、信息保留
|
||||
- 对话记录保留 30 天后自动删除
|
||||
- 您可以随时删除自己的健康数据和对话记录
|
||||
- 账号注销后,所有数据将在 7 天内永久删除
|
||||
|
||||
### 五、您的权利
|
||||
- 查看和导出您的个人数据
|
||||
- 修改不准确的个人信息
|
||||
- 删除不需要的数据
|
||||
- 注销账号并清除所有数据
|
||||
- 关闭推送通知
|
||||
|
||||
### 六、联系我们
|
||||
如有任何关于隐私的问题,请联系:
|
||||
邮箱:privacy@healthbutler.com
|
||||
电话:400-xxx-xxxx''',
|
||||
'about': '''## 关于健康管家
|
||||
|
||||
版本:v1.0.0 (Build 20260101)
|
||||
|
||||
### 产品介绍
|
||||
健康管家是一款面向心脏术后康复患者的私人 AI 健康管理应用。以对话为核心交互方式,患者可以通过自然语言记录健康数据、获取饮食运动建议、管理用药、解读检查报告。
|
||||
|
||||
### 核心功能
|
||||
- AI 智能问诊:基于大语言模型的健康咨询服务
|
||||
- 健康数据管理:血压、心率、血糖、血氧、体重的记录与趋势分析
|
||||
- 智能用药管理:AI 解析处方,自动生成用药计划和提醒
|
||||
- 饮食识别分析:拍照即可识别食物种类、估算热量营养素
|
||||
- 报告智能解读:上传检查报告,AI 自动提取指标并预解读
|
||||
- 运动计划管理:制定和追踪每日运动目标
|
||||
- 在线医生问诊:与签约医生进行远程咨询
|
||||
|
||||
### 开发团队
|
||||
由专业医疗团队与 AI 技术团队联合打造。
|
||||
|
||||
### 技术支持
|
||||
如遇到问题或有建议,请通过以下方式联系我们:
|
||||
- 在线客服:App 内「设置」→「意见反馈」
|
||||
- 客服热线:400-xxx-xxxx(工作日 9:00-18:00)
|
||||
|
||||
### 版权声明
|
||||
© 2025-2026 健康管家团队。保留所有权利。
|
||||
本软件受中华人民共和国著作权法保护。''',
|
||||
};
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(icon: const Icon(Icons.chevron_left), onPressed: () => popRoute(ref)),
|
||||
title: Text(titles[type] ?? '', style: const TextStyle(color: Color(0xFF1A1A1A), fontWeight: FontWeight.w600)),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(contents[type] ?? '内容加载中...', style: const TextStyle(fontSize: 14, height: 1.8, color: Color(0xFF333333))),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
health_app/lib/pages/report/ai_analysis_page.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
class AiAnalysisPage extends ConsumerWidget {
|
||||
const AiAnalysisPage({super.key});
|
||||
|
||||
@override Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(backgroundColor: Colors.white, elevation: 0, leading: IconButton(icon: const Icon(Icons.chevron_left), onPressed: () => Navigator.pop(context)), title: _buildTitle(), centerTitle: true, actions: [IconButton(icon: const Icon(Icons.more_vert), color: const Color(0xFF666666), onPressed: () {})]),
|
||||
body: SingleChildScrollView(padding: const EdgeInsets.all(16), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [_buildReportPreview(), const SizedBox(height: 20), _buildIndicators(), const SizedBox(height: 24), _buildAiInterpretation(), const SizedBox(height: 24), _buildDoctorAdvice(), const SizedBox(height: 24), _buildHealthTips()])),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTitle() {
|
||||
return Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4), decoration: BoxDecoration(color: const Color(0xFF8B9CF7).withAlpha(15), borderRadius: BorderRadius.circular(12)), child: Row(mainAxisSize: MainAxisSize.min, children: [const Icon(Icons.auto_awesome, size: 16, color: Color(0xFF8B9CF7)), const SizedBox(width: 4), const Text('AI预解读', style: TextStyle(fontSize: 13, color: Color(0xFF8B9CF7), fontWeight: FontWeight.w500))])),
|
||||
const SizedBox(width: 4), Text('血常规检查', style: TextStyle(color: Colors.grey[800], fontWeight: FontWeight.w600)),
|
||||
]);
|
||||
}
|
||||
|
||||
Widget _buildReportPreview() => Container(width: double.infinity, height: 180, decoration: BoxDecoration(color: const Color(0xFFF0F2FF), borderRadius: BorderRadius.circular(16), border: Border.all(color: const Color(0xFFD8DCFD), width: 1.5)), child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [Icon(Icons.description_outlined, size: 48, color: Colors.grey[400]), const SizedBox(height: 8), Text('检查报告图片', style: TextStyle(fontSize: 14, color: Colors.grey[600]))]));
|
||||
|
||||
Widget _buildIndicators() {
|
||||
final indicators = [{'name': '红细胞 (RBC)', 'value': '4.68', 'unit': '(×10¹²/L)', 'ref': '4.0-5.50', 'status': 'normal'}, {'name': '白细胞 (WBC)', 'value': '6.55', 'unit': '(×10⁹/L)', 'ref': '3.5-9.50', 'status': 'normal'}, {'name': '血红蛋白 (HGB)', 'value': '135', 'unit': '(g/L)', 'ref': '120-175', 'status': 'normal'}, {'name': '血小板 (PLT)', 'value': '235', 'unit': '(×10⁹/L)', 'ref': '125-350', 'status': 'normal'}];
|
||||
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [const Text('指标详情', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))), const SizedBox(height: 12), ...indicators.map((item) => _indicatorCard(item))]);
|
||||
}
|
||||
|
||||
Widget _indicatorCard(Map<String, dynamic> item) {
|
||||
final isNormal = item['status'] == 'normal';
|
||||
return Container(margin: const EdgeInsets.only(bottom: 10), padding: const EdgeInsets.all(14), decoration: BoxDecoration(color: isNormal ? const Color(0xFFF8FDFB) : const Color(0xFFFFF8F5), borderRadius: BorderRadius.circular(14), border: Border.all(color: isNormal ? const Color(0xFFD4EDDA) : const Color(0xFFFFD7C5))), child: Row(children: [Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Text(item['name']?.toString() ?? '', style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Color(0xFF333333))), const SizedBox(height: 4), Text('参考范围:${item['ref']?.toString() ?? ''}', style: TextStyle(fontSize: 12, color: Colors.grey[500]))])), Column(crossAxisAlignment: CrossAxisAlignment.end, children: [Text('${item['value']?.toString() ?? ''} ${item['unit']?.toString() ?? ''}', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1A1A1A))), const SizedBox(height: 2), Container(padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), decoration: BoxDecoration(color: isNormal ? const Color(0xFF43A047).withAlpha(20) : const Color(0xFFFF9800).withAlpha(20), borderRadius: BorderRadius.circular(8)), child: Text(isNormal ? '正常' : '偏高', style: TextStyle(fontSize: 11, color: isNormal ? const Color(0xFF43A047) : const Color(0xFFFF9800))))])]));
|
||||
}
|
||||
|
||||
Widget _buildAiInterpretation() => Container(width: double.infinity, padding: const EdgeInsets.all(16), decoration: BoxDecoration(color: const Color(0xFFF0F2FF), borderRadius: BorderRadius.circular(16)), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Row(children: [Icon(Icons.auto_awesome, size: 18, color: const Color(0xFF8B9CF7)), const SizedBox(width: 6), Text('AI 智能解读', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))), const Spacer(), Container(padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3), decoration: BoxDecoration(color: const Color(0xFF8B9CF7).withAlpha(15), borderRadius: BorderRadius.circular(10)), child: const Text('已分析', style: TextStyle(fontSize: 11, color: Color(0xFF8B9CF7))))]), const SizedBox(height: 12), const Text('您的血常规检查结果基本正常,各项指标均在参考范围内。红细胞、白细胞、血小板计数均处于健康水平,血红蛋白含量充足,说明您的造血功能和免疫功能良好。建议继续保持良好的生活习惯,定期复查。', style: TextStyle(fontSize: 14, height: 1.6, color: Color(0xFF444444)))]));
|
||||
|
||||
Widget _buildDoctorAdvice() => Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Row(children: [CircleAvatar(radius: 16, backgroundColor: const Color(0xFFF0F2FF), child: const Icon(Icons.local_hospital, size: 16, color: Color(0xFF8B9CF7))), const SizedBox(width: 8), const Text('医生建议', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)))]), const SizedBox(height: 12), Container(width: double.infinity, padding: const EdgeInsets.all(14), decoration: BoxDecoration(borderRadius: BorderRadius.circular(14), border: Border.all(color: const Color(0xFFEEEEEE))), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [_adviceItem('李医生', '心内科', '各项指标正常,继续保持。注意低盐饮食,适当运动。'), const Divider(), _adviceItem('王医生', '全科', '血常规结果理想,无需特殊处理。下次体检可关注血脂指标.')]))]);
|
||||
|
||||
Widget _adviceItem(String name, String dept, String advice) => Padding(padding: const EdgeInsets.symmetric(vertical: 8), child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [CircleAvatar(radius: 14, backgroundColor: const Color(0xFFF0F2FF), child: Text(name[0], style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xFF8B9CF7)))), const SizedBox(width: 10), Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Row(children: [Text(name, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Color(0xFF333333))), const SizedBox(width: 6), Text(dept, style: TextStyle(fontSize: 12, color: Colors.grey[500]))]), const SizedBox(height: 4), Text(advice, style: TextStyle(fontSize: 13, color: Colors.grey[700], height: 1.4))]))]));
|
||||
|
||||
Widget _buildHealthTips() => Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Row(children: [Icon(Icons.lightbulb_outline, size: 18, color: const Color(0xFFFFB800)), const SizedBox(width: 8), const Text('健康提示', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)))]), const SizedBox(height: 12), ...['定期进行血常规检查,建议每半年一次', '保持均衡饮食,多吃富含铁和维生素的食物', '适度运动,每周至少150分钟中等强度有氧运动', '保证充足睡眠,每晚7-8小时'].map((tip) => Padding(padding: const EdgeInsets.only(bottom: 8), child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [Container(margin: const EdgeInsets.only(top: 6), width: 6, height: 6, decoration: const BoxDecoration(color: Color(0xFFFFB800), shape: BoxShape.circle)), const SizedBox(width: 10), Expanded(child: Text(tip, style: TextStyle(fontSize: 14, color: Colors.grey[700], height: 1.4)))])))]);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ class ReportListPage extends ConsumerWidget {
|
||||
appBar: AppBar(title: const Text('看报告')),
|
||||
body: const Center(
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
CircularProgressIndicator(color: Color(0xFF635BFF)),
|
||||
CircularProgressIndicator(color: Color(0xFF8B9CF7)),
|
||||
SizedBox(height: 16),
|
||||
Text('AI 正在分析报告...'),
|
||||
]),
|
||||
@@ -209,7 +209,7 @@ class ReportListPage extends ConsumerWidget {
|
||||
Widget _buildUploadButton(BuildContext context, WidgetRef ref) {
|
||||
return FloatingActionButton(
|
||||
onPressed: () => _showUploadOptions(context, ref),
|
||||
backgroundColor: const Color(0xFF635BFF),
|
||||
backgroundColor: const Color(0xFF8B9CF7),
|
||||
child: const Icon(Icons.add),
|
||||
);
|
||||
}
|
||||
@@ -266,10 +266,10 @@ class ReportListPage extends ConsumerWidget {
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F3FF),
|
||||
color: const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(60),
|
||||
),
|
||||
child: const Icon(Icons.file_open, size: 48, color: Color(0xFF635BFF)),
|
||||
child: const Icon(Icons.file_open, size: 48, color: Color(0xFF8B9CF7)),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Text('暂无检查报告', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
|
||||
@@ -285,14 +285,14 @@ class ReportListPage extends ConsumerWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF635BFF).withAlpha(10), blurRadius: 4, offset: const Offset(0, 2))],
|
||||
boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(10), blurRadius: 4, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: ListTile(
|
||||
leading: Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F3FF),
|
||||
color: const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: _getReportIcon(report.type),
|
||||
@@ -315,13 +315,13 @@ class ReportListPage extends ConsumerWidget {
|
||||
|
||||
Widget _getReportIcon(String type) {
|
||||
final icons = {
|
||||
'血液检查': const Icon(Icons.bloodtype, size: 24, color: Color(0xFF635BFF)),
|
||||
'心电图': const Icon(Icons.monitor_heart, size: 24, color: Color(0xFF635BFF)),
|
||||
'超声检查': const Icon(Icons.image, size: 24, color: Color(0xFF635BFF)),
|
||||
'影像报告': const Icon(Icons.image, size: 24, color: Color(0xFF635BFF)),
|
||||
'PDF文档': const Icon(Icons.picture_as_pdf, size: 24, color: Color(0xFF635BFF)),
|
||||
'血液检查': const Icon(Icons.bloodtype, size: 24, color: Color(0xFF8B9CF7)),
|
||||
'心电图': const Icon(Icons.monitor_heart, size: 24, color: Color(0xFF8B9CF7)),
|
||||
'超声检查': const Icon(Icons.image, size: 24, color: Color(0xFF8B9CF7)),
|
||||
'影像报告': const Icon(Icons.image, size: 24, color: Color(0xFF8B9CF7)),
|
||||
'PDF文档': const Icon(Icons.picture_as_pdf, size: 24, color: Color(0xFF8B9CF7)),
|
||||
};
|
||||
return icons[type] ?? const Icon(Icons.description, size: 24, color: Color(0xFF635BFF));
|
||||
return icons[type] ?? const Icon(Icons.description, size: 24, color: Color(0xFF8B9CF7));
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
@@ -369,6 +369,35 @@ class ReportDetailPage extends ConsumerWidget {
|
||||
_buildAnalysisSection(analysis),
|
||||
const SizedBox(height: 20),
|
||||
_buildSummarySection(analysis),
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('图片加载中...'), duration: Duration(seconds: 2)),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.image),
|
||||
label: const Text('查看原始图片'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF8B9CF7),
|
||||
side: const BorderSide(color: Color(0xFF8B9CF7)),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => pushRoute(ref, 'aiAnalysis'),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFF8B9CF7), foregroundColor: Colors.white, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24))),
|
||||
child: const Text('查看 AI 智能解读'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
]),
|
||||
),
|
||||
@@ -379,7 +408,7 @@ class ReportDetailPage extends ConsumerWidget {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F3FF),
|
||||
color: const Color(0xFFF0F2FF),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
@@ -401,7 +430,7 @@ class ReportDetailPage extends ConsumerWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: const Color(0xFFE8E6FF), width: 1.5),
|
||||
border: Border.all(color: const Color(0xFFD8DCFD), width: 1.5),
|
||||
),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Padding(
|
||||
@@ -412,6 +441,27 @@ class ReportDetailPage extends ConsumerWidget {
|
||||
const Text('指标分析', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
]),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF3E0),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFFFE0B2)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 16, color: Color(0xFFE65100)),
|
||||
const SizedBox(width: 6),
|
||||
const Text(
|
||||
'AI 预解读 · 待医生确认',
|
||||
style: TextStyle(fontSize: 13, color: Color(0xFFE65100), fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
...analysis.indicators.map((ind) => _buildIndicatorRow(ind)),
|
||||
]),
|
||||
);
|
||||
|
||||
216
health_app/lib/pages/settings/notification_prefs_page.dart
Normal file
@@ -0,0 +1,216 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
|
||||
// ── 通知偏好状态 ──
|
||||
|
||||
final notificationPrefsProvider = NotifierProvider<NotificationPrefsNotifier, Map<String, bool>>(
|
||||
NotificationPrefsNotifier.new,
|
||||
);
|
||||
|
||||
class NotificationPrefsNotifier extends Notifier<Map<String, bool>> {
|
||||
@override
|
||||
Map<String, bool> build() {
|
||||
// TODO: 从 SQLite 读取持久化值,此处先用默认值
|
||||
return {
|
||||
'medication': true,
|
||||
'healthAlert': true,
|
||||
'followUp': true,
|
||||
'aiReply': false,
|
||||
'dndEnabled': false,
|
||||
'pushEnabled': true,
|
||||
'dndStart': false, // 占位:实际用 TimeOfDay
|
||||
'dndEnd': false,
|
||||
};
|
||||
}
|
||||
|
||||
void toggle(String key) {
|
||||
state = {...state, key: !state[key]!};
|
||||
// TODO: 持久化到 SQLite
|
||||
}
|
||||
|
||||
void setDndStart(TimeOfDay time) {
|
||||
state = {...state, 'dndStart': true}; // 简化存储
|
||||
}
|
||||
|
||||
void setDndEnd(TimeOfDay time) {
|
||||
state = {...state, 'dndEnd': true};
|
||||
}
|
||||
}
|
||||
|
||||
// ── 页面 ──
|
||||
|
||||
class NotificationPrefsPage extends ConsumerWidget {
|
||||
const NotificationPrefsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final prefs = ref.watch(notificationPrefsProvider);
|
||||
final dndOn = prefs['dndEnabled'] ?? false;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8F9FC),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios_new, color: Color(0xFF1A1A1A)),
|
||||
onPressed: () => popRoute(ref),
|
||||
),
|
||||
title: const Text('消息通知', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// ── 推送总开关 ──
|
||||
_SectionTitle(title: '推送通知'),
|
||||
_SwitchTile(
|
||||
title: '允许推送通知',
|
||||
subtitle: '关闭后将不再收到任何系统推送',
|
||||
value: prefs['pushEnabled'] ?? true,
|
||||
onChanged: (v) => ref.read(notificationPrefsProvider.notifier).toggle('pushEnabled'),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// ── 各类通知开关 ──
|
||||
_SectionTitle(title: '通知类型'),
|
||||
_SwitchTile(
|
||||
icon: Icons.medication_rounded,
|
||||
iconBg: const Color(0xFFFFF3E0),
|
||||
iconColor: const Color(0xFFFF9800),
|
||||
title: '用药提醒',
|
||||
subtitle: '服药时间到达时提醒您',
|
||||
value: prefs['medication'] ?? true,
|
||||
onChanged: (v) => ref.read(notificationPrefsProvider.notifier).toggle('medication'),
|
||||
),
|
||||
_SwitchTile(
|
||||
icon: Icons.warning_amber_rounded,
|
||||
iconBg: const Color(0xFFFFEBEE),
|
||||
iconColor: const Color(0xFFE53935),
|
||||
title: '健康异常提醒',
|
||||
subtitle: '检测到数据异常时及时通知',
|
||||
value: prefs['healthAlert'] ?? true,
|
||||
onChanged: (v) => ref.read(notificationPrefsProvider.notifier).toggle('healthAlert'),
|
||||
),
|
||||
_SwitchTile(
|
||||
icon: Icons.event_available_rounded,
|
||||
iconBg: const Color(0xFFE8F5E9),
|
||||
iconColor: const Color(0xFF4CAF50),
|
||||
title: '复查日期提醒',
|
||||
subtitle: '复查日前一天提醒您预约',
|
||||
value: prefs['followUp'] ?? true,
|
||||
onChanged: (v) => ref.read(notificationPrefsProvider.notifier).toggle('followUp'),
|
||||
),
|
||||
_SwitchTile(
|
||||
icon: Icons.smart_toy_outlined,
|
||||
iconBg: const Color(0xFFF3E5F5),
|
||||
iconColor: const Color(0xFF8B9CF7),
|
||||
title: 'AI 回复通知',
|
||||
subtitle: 'AI 助手回复时发送通知',
|
||||
value: prefs['aiReply'] ?? false,
|
||||
onChanged: (v) => ref.read(notificationPrefsProvider.notifier).toggle('aiReply'),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// ── 免打扰时段 ──
|
||||
_SectionTitle(title: '免打扰时段'),
|
||||
_SwitchTile(
|
||||
title: '开启免打扰模式',
|
||||
subtitle: dndOn ? '22:00 - 08:00 期间静音' : '关闭后全天接收通知',
|
||||
value: dndOn,
|
||||
onChanged: (v) => ref.read(notificationPrefsProvider.notifier).toggle('dndEnabled'),
|
||||
),
|
||||
if (dndOn) ...[
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(12)),
|
||||
child: Row(children: [
|
||||
Expanded(child: _TimeButton(label: '开始', time: '22:00', onTap: () async {
|
||||
final picked = await showTimePicker(context: context, initialTime: const TimeOfDay(hour: 22, minute: 0));
|
||||
if (picked != null && context.mounted) ref.read(notificationPrefsProvider.notifier).setDndStart(picked);
|
||||
})),
|
||||
Padding(padding: const EdgeInsets.symmetric(horizontal: 12), child: Text('~', style: TextStyle(fontSize: 16, color: Colors.grey[400]))),
|
||||
Expanded(child: _TimeButton(label: '结束', time: '08:00', onTap: () async {
|
||||
final picked = await showTimePicker(context: context, initialTime: const TimeOfDay(hour: 8, minute: 0));
|
||||
if (picked != null && context.mounted) ref.read(notificationPrefsProvider.notifier).setDndEnd(picked);
|
||||
})),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 子组件 ──
|
||||
|
||||
class _SectionTitle extends StatelessWidget {
|
||||
final String title;
|
||||
const _SectionTitle({required this.title});
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(padding: const EdgeInsets.only(left: 4, bottom: 10), child: Text(title, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF999999))));
|
||||
}
|
||||
}
|
||||
|
||||
class _SwitchTile extends StatelessWidget {
|
||||
final IconData? icon;
|
||||
final Color? iconBg;
|
||||
final Color? iconColor;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final bool value;
|
||||
final ValueChanged<bool> onChanged;
|
||||
|
||||
const _SwitchTile({
|
||||
this.icon, this.iconBg, this.iconColor,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 3),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(12)),
|
||||
child: Row(children: [
|
||||
if (icon != null) ...[
|
||||
Container(width: 38, height: 38, decoration: BoxDecoration(color: iconBg, borderRadius: BorderRadius.circular(10)), child: Icon(icon, size: 20, color: iconColor)),
|
||||
const SizedBox(width: 12),
|
||||
],
|
||||
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(title, style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A), fontWeight: FontWeight.w500)),
|
||||
if (subtitle != null && subtitle!.isNotEmpty) Text(subtitle!, style: TextStyle(fontSize: 12, color: Colors.grey[500])),
|
||||
])),
|
||||
Switch(value: value, onChanged: onChanged, activeThumbColor: const Color(0xFF8B9CF7), activeTrackColor: const Color(0xFFC5BFFF)),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TimeButton extends StatelessWidget {
|
||||
final String label;
|
||||
final String time;
|
||||
final VoidCallback onTap;
|
||||
const _TimeButton({required this.label, required this.time, required this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(onTap: onTap, child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(border: Border.all(color: const Color(0xFFE0E0E0)), borderRadius: BorderRadius.circular(10)),
|
||||
child: Column(children: [Text(label, style: TextStyle(fontSize: 11, color: Colors.grey[500])), Text(time, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF8B9CF7)))]),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -3,65 +3,83 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
import '../../providers/auth_provider.dart';
|
||||
|
||||
/// 设置页
|
||||
class SettingsPage extends ConsumerWidget {
|
||||
const SettingsPage({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) => Scaffold(
|
||||
appBar: AppBar(title: const Text('设置')),
|
||||
body: ListView(children: [
|
||||
_SetItem(icon: Icons.shield, title: '隐私保护中心', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'privacy'})),
|
||||
_SetItem(icon: Icons.notifications, title: '通知偏好', onTap: () => pushRoute(ref, 'notificationPrefs')),
|
||||
_SetItem(icon: Icons.text_fields, title: '字体大小', trailing: _FontSlider()),
|
||||
_SetItem(icon: Icons.article, title: '协议与公告', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'terms'})),
|
||||
_SetItem(icon: Icons.info, title: '关于', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'about'})),
|
||||
const Divider(),
|
||||
_SetItem(icon: Icons.logout, title: '退出登录', textColor: const Color(0xFFE53935), onTap: () async {
|
||||
final ok = await showDialog<bool>(context: context, builder: (ctx) => AlertDialog(
|
||||
title: const Text('退出登录'), content: const Text('确定退出?'),
|
||||
actions: [TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')), TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定'))]));
|
||||
if (ok == true) { await ref.read(authProvider.notifier).logout(); goRoute(ref, 'login'); }
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
@override Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8F9FC),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(icon: const Icon(Icons.chevron_left), onPressed: () => popRoute(ref)),
|
||||
title: const Text('设置', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(child: SingleChildScrollView(padding: const EdgeInsets.only(bottom: 30), child: Column(children: [
|
||||
const SizedBox(height: 12),
|
||||
_SetItem(icon: Icons.notifications_outlined, title: '消息通知', onTap: () => pushRoute(ref, 'notificationPrefs')),
|
||||
_SetItem(icon: Icons.medication_outlined, title: '用药提醒', subtitle: 'mmHg / mmol/L', onTap: () => pushRoute(ref, 'medications')),
|
||||
_SetItem(icon: Icons.data_usage_outlined, title: '数据导出', onTap: () {}),
|
||||
_SetItem(icon: Icons.text_fields_outlined, title: '字体大小', trailingText: 'v1.0.0', onTap: () {}),
|
||||
_SetItem(icon: Icons.cleaning_services_outlined, title: '清除缓存', subtitle: '73.2 MB', onTap: () {}),
|
||||
_SetItem(icon: Icons.info_outline, title: '关于健康管家', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'about'})),
|
||||
_SetItem(icon: Icons.shield_outlined, title: '隐私协议', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'privacy'})),
|
||||
const SizedBox(height: 30),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('退出登录'),
|
||||
content: const Text('确定退出?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')),
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定')),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ok == true) { await ref.read(authProvider.notifier).logout(); goRoute(ref, 'login'); }
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 24),
|
||||
height: 50,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(border: Border.all(color: const Color(0xFFE53935)), borderRadius: BorderRadius.circular(25)),
|
||||
child: const Text('退出登录', style: TextStyle(fontSize: 16, color: Color(0xFFE53935), fontWeight: FontWeight.w500)),
|
||||
),
|
||||
),
|
||||
]))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SetItem extends StatelessWidget {
|
||||
final IconData icon; final String title; final VoidCallback? onTap; final Widget? trailing; final Color? textColor;
|
||||
const _SetItem({required this.icon, required this.title, this.onTap, this.trailing, this.textColor});
|
||||
@override
|
||||
Widget build(BuildContext context) => ListTile(leading: Icon(icon, color: const Color(0xFF666666)), title: Text(title, style: TextStyle(fontSize: 16, color: textColor)), trailing: trailing ?? const Icon(Icons.chevron_right, size: 20), onTap: onTap);
|
||||
}
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final String? trailingText;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
class _FontSlider extends StatefulWidget {
|
||||
@override State<_FontSlider> createState() => _FontSliderState();
|
||||
}
|
||||
class _FontSliderState extends State<_FontSlider> {
|
||||
double _value = 1.0;
|
||||
@override Widget build(BuildContext context) => SizedBox(width: 120, child: Slider(value: _value, min: 0.8, max: 1.6, divisions: 8, label: '${_value.toStringAsFixed(1)}x', onChanged: (v) => setState(() => _value = v)));
|
||||
}
|
||||
const _SetItem({required this.icon, required this.title, this.subtitle, this.trailingText, this.onTap});
|
||||
|
||||
/// 通知偏好页
|
||||
class NotificationPrefsPage extends ConsumerWidget {
|
||||
const NotificationPrefsPage({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) => Scaffold(
|
||||
appBar: AppBar(title: const Text('通知偏好')),
|
||||
body: ListView(children: [
|
||||
_SwitchTile(icon: Icons.medication, title: '用药提醒'),
|
||||
_SwitchTile(icon: Icons.calendar_month, title: '复查提醒'),
|
||||
_SwitchTile(icon: Icons.chat, title: '医生回复'),
|
||||
_SwitchTile(icon: Icons.warning_amber, title: '异常警告'),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
class _SwitchTile extends StatefulWidget {
|
||||
final IconData icon; final String title;
|
||||
const _SwitchTile({required this.icon, required this.title});
|
||||
@override State<_SwitchTile> createState() => _SwitchTileState();
|
||||
}
|
||||
class _SwitchTileState extends State<_SwitchTile> {
|
||||
bool _on = true;
|
||||
@override Widget build(BuildContext context) => SwitchListTile(secondary: Icon(widget.icon), title: Text(widget.title), value: _on, onChanged: (v) => setState(() => _on = v));
|
||||
@override Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 24, vertical: 2),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 14),
|
||||
decoration: BoxDecoration(color: Colors.white),
|
||||
child: Row(children: [
|
||||
Container(width: 36, height: 36, decoration: BoxDecoration(color: const Color(0xFFF0F2FF), borderRadius: BorderRadius.circular(10)), child: Icon(icon, size: 18, color: const Color(0xFF8B9CF7))),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Text(title, style: const TextStyle(fontSize: 16, color: Color(0xFF1A1A1A))), if (subtitle != null && subtitle!.isNotEmpty) Text(subtitle!, style: TextStyle(fontSize: 13, color: Colors.grey[500]))])),
|
||||
if (trailingText != null && trailingText!.isNotEmpty) Text(trailingText!, style: TextStyle(fontSize: 14, color: Colors.grey[400])),
|
||||
if (trailingText == null || trailingText!.isEmpty) const SizedBox(),
|
||||
Icon(Icons.chevron_right, size: 20, color: Colors.grey[300]),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'auth_provider.dart';
|
||||
import 'data_providers.dart';
|
||||
import '../utils/sse_handler.dart';
|
||||
|
||||
enum MessageType { text, dataConfirm, medicationConfirm, dietAnalysis, reportAnalysis, quickOptions }
|
||||
enum MessageType { text, dataConfirm, medicationConfirm, dietAnalysis, reportAnalysis, quickOptions, agentWelcome, taskCard }
|
||||
|
||||
class ChatMessage {
|
||||
final String id;
|
||||
@@ -94,7 +95,7 @@ final conversationListProvider = FutureProvider<List<ConversationItem>>((ref) as
|
||||
);
|
||||
}).toList();
|
||||
} catch (_) {
|
||||
return _mockConversations;
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
@@ -110,39 +111,85 @@ ActiveAgent _parseAgent(String? type) {
|
||||
}
|
||||
}
|
||||
|
||||
final _mockConversations = [
|
||||
ConversationItem(
|
||||
id: '1',
|
||||
title: '用药咨询',
|
||||
lastMessage: '阿司匹林应该什么时候吃?',
|
||||
updatedAt: DateTime.now().subtract(const Duration(hours: 2)),
|
||||
agent: ActiveAgent.medication,
|
||||
),
|
||||
ConversationItem(
|
||||
id: '2',
|
||||
title: '血压偏高',
|
||||
lastMessage: '血压145/90,需要注意什么?',
|
||||
updatedAt: DateTime.now().subtract(const Duration(hours: 5)),
|
||||
agent: ActiveAgent.health,
|
||||
),
|
||||
ConversationItem(
|
||||
id: '3',
|
||||
title: '饮食建议',
|
||||
lastMessage: '今天吃了米饭和红烧肉',
|
||||
updatedAt: DateTime.now().subtract(const Duration(days: 1)),
|
||||
agent: ActiveAgent.diet,
|
||||
),
|
||||
];
|
||||
|
||||
class ChatNotifier extends Notifier<ChatState> {
|
||||
StreamSubscription<Map<String, dynamic>>? _subscription;
|
||||
|
||||
@override
|
||||
ChatState build() => const ChatState();
|
||||
ChatState build() {
|
||||
// 首次加载时插入今日任务卡片作为第一条消息
|
||||
Future.microtask(() => insertTaskCard());
|
||||
return const ChatState();
|
||||
}
|
||||
|
||||
void insertTaskCard() {
|
||||
if (state.messages.any((m) => m.type == MessageType.taskCard)) return;
|
||||
state = state.copyWith(messages: [ChatMessage(
|
||||
id: 'task_card',
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
createdAt: DateTime.now(),
|
||||
type: MessageType.taskCard,
|
||||
), ...state.messages]);
|
||||
}
|
||||
|
||||
void setAgent(ActiveAgent a) {
|
||||
_subscription?.cancel();
|
||||
state = state.activeAgent == a ? const ChatState() : ChatState(activeAgent: a);
|
||||
state = state.copyWith(activeAgent: a);
|
||||
}
|
||||
|
||||
void insertAgentWelcome(ActiveAgent agent) {
|
||||
state = state.copyWith(messages: [...state.messages, ChatMessage(
|
||||
id: 'welcome_${agent.name}_${DateTime.now().millisecondsSinceEpoch}',
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
createdAt: DateTime.now(),
|
||||
type: MessageType.agentWelcome,
|
||||
metadata: {'agent': agent.name},
|
||||
)]);
|
||||
}
|
||||
|
||||
Future<void> sendImage(String imagePath, String text) async {
|
||||
final file = File(imagePath);
|
||||
if (!await file.exists()) return;
|
||||
|
||||
// 先显示用户消息(本地显示图片路径)
|
||||
final userMsg = ChatMessage(
|
||||
id: '${DateTime.now().millisecondsSinceEpoch}',
|
||||
role: 'user',
|
||||
content: text.isNotEmpty ? text : '[图片]',
|
||||
createdAt: DateTime.now(),
|
||||
metadata: {'localImagePath': imagePath},
|
||||
);
|
||||
state = state.copyWith(messages: [...state.messages, userMsg]);
|
||||
|
||||
// 异步上传图片
|
||||
String? uploadedUrl;
|
||||
try {
|
||||
final api = ref.read(apiClientProvider);
|
||||
uploadedUrl = await api.uploadFile('/api/upload', file);
|
||||
} catch (_) {
|
||||
// 上传失败:保留本地路径,仍然可以本地显示
|
||||
}
|
||||
|
||||
// 更新消息元数据(保留本地路径 + 添加远程URL)
|
||||
final updatedMsgs = state.messages.toList();
|
||||
final idx = updatedMsgs.indexWhere((m) => m.id == userMsg.id);
|
||||
if (idx >= 0) {
|
||||
final meta = <String, dynamic>{'localImagePath': imagePath};
|
||||
if (uploadedUrl != null) meta['imageUrl'] = uploadedUrl;
|
||||
updatedMsgs[idx] = ChatMessage(
|
||||
id: userMsg.id,
|
||||
role: 'user',
|
||||
content: userMsg.content,
|
||||
createdAt: userMsg.createdAt,
|
||||
metadata: meta,
|
||||
);
|
||||
state = state.copyWith(messages: updatedMsgs);
|
||||
}
|
||||
|
||||
// 将图片 URL 作为消息内容发送给 AI
|
||||
final msgWithImage = text.isNotEmpty ? '$text\n[图片已上传]' : '[图片已上传]';
|
||||
await _sendToAI(msgWithImage);
|
||||
}
|
||||
|
||||
Future<void> sendMessage(String text) async {
|
||||
@@ -157,6 +204,10 @@ class ChatNotifier extends Notifier<ChatState> {
|
||||
state = state.copyWith(
|
||||
messages: [...state.messages, userMsg], isStreaming: true);
|
||||
|
||||
await _sendToAI(text);
|
||||
}
|
||||
|
||||
Future<void> _sendToAI(String text) async {
|
||||
final aiMsg = ChatMessage(
|
||||
id: '${DateTime.now().millisecondsSinceEpoch}_ai',
|
||||
role: 'assistant',
|
||||
@@ -164,6 +215,8 @@ class ChatNotifier extends Notifier<ChatState> {
|
||||
createdAt: DateTime.now(),
|
||||
);
|
||||
|
||||
state = state.copyWith(isStreaming: true);
|
||||
|
||||
try {
|
||||
final token = await ref.read(apiClientProvider).accessToken;
|
||||
if (token == null) {
|
||||
@@ -236,6 +289,7 @@ class ChatNotifier extends Notifier<ChatState> {
|
||||
case 'diet_analysis': return MessageType.dietAnalysis;
|
||||
case 'report_analysis': return MessageType.reportAnalysis;
|
||||
case 'quick_options': return MessageType.quickOptions;
|
||||
case 'agent_welcome': return MessageType.agentWelcome;
|
||||
default: return MessageType.text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'auth_provider.dart';
|
||||
import '../services/health_service.dart';
|
||||
|
||||
final exerciseServiceProvider = Provider<ExerciseService>((ref) {
|
||||
return ExerciseService(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
/// 健康数据服务
|
||||
final healthServiceProvider = Provider<HealthService>((ref) {
|
||||
return HealthService(ref.watch(apiClientProvider));
|
||||
@@ -23,10 +27,6 @@ final consultationServiceProvider = Provider<ConsultationService>((ref) {
|
||||
return ConsultationService(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
final exerciseServiceProvider = Provider<ExerciseService>((ref) {
|
||||
return ExerciseService(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
/// 最新健康数据 Provider
|
||||
final latestHealthProvider = FutureProvider<Map<String, dynamic>>((ref) async {
|
||||
final service = ref.watch(healthServiceProvider);
|
||||
@@ -45,12 +45,45 @@ final medicationListProvider = FutureProvider<List<Map<String, dynamic>>>((ref)
|
||||
return service.getList();
|
||||
});
|
||||
|
||||
final medicationReminderProvider = FutureProvider<List<Map<String, dynamic>>>((ref) async {
|
||||
final service = ref.watch(medicationServiceProvider);
|
||||
return service.getReminders();
|
||||
});
|
||||
|
||||
/// 医生列表 Provider
|
||||
final doctorListProvider = FutureProvider<List<Map<String, dynamic>>>((ref) async {
|
||||
final service = ref.watch(consultationServiceProvider);
|
||||
return service.getDoctors();
|
||||
try {
|
||||
return await service.getDoctors().timeout(const Duration(seconds: 8));
|
||||
} catch (_) {
|
||||
return _fallbackDoctors;
|
||||
}
|
||||
});
|
||||
|
||||
const _fallbackDoctors = [
|
||||
{
|
||||
'id': 'doc_1',
|
||||
'name': '张医生',
|
||||
'title': '主任医师',
|
||||
'department': '心内科',
|
||||
'introduction': '擅长冠心病、高血压术后管理,20年临床经验',
|
||||
},
|
||||
{
|
||||
'id': 'doc_2',
|
||||
'name': '李医生',
|
||||
'title': '副主任医师',
|
||||
'department': '内分泌科',
|
||||
'introduction': '擅长糖尿病、甲状腺疾病管理,15年临床经验',
|
||||
},
|
||||
{
|
||||
'id': 'doc_3',
|
||||
'name': '王医生',
|
||||
'title': '主治医师',
|
||||
'department': '营养科',
|
||||
'introduction': '擅长术后营养指导、饮食方案制定,10年临床经验',
|
||||
},
|
||||
];
|
||||
|
||||
/// 问诊配额 Provider
|
||||
final consultationQuotaProvider = FutureProvider<Map<String, dynamic>>((ref) async {
|
||||
final service = ref.watch(consultationServiceProvider);
|
||||
@@ -60,5 +93,30 @@ final consultationQuotaProvider = FutureProvider<Map<String, dynamic>>((ref) asy
|
||||
/// 当前运动计划 Provider
|
||||
final currentExercisePlanProvider = FutureProvider<Map<String, dynamic>?>((ref) async {
|
||||
final service = ref.watch(exerciseServiceProvider);
|
||||
return service.getCurrentPlan();
|
||||
try {
|
||||
return await service.getCurrentPlan().timeout(const Duration(seconds: 8));
|
||||
} catch (_) {
|
||||
final today = DateTime.now();
|
||||
final monday = today.subtract(Duration(days: today.weekday - 1));
|
||||
return {
|
||||
'weekStartDate': '${monday.year}-${monday.month.toString().padLeft(2, '0')}-${monday.day.toString().padLeft(2, '0')}',
|
||||
'items': List.generate(7, (i) => {
|
||||
'id': 'local_$i',
|
||||
'dayOfWeek': i,
|
||||
'exerciseType': i == 2 || i == 5 ? '休息' : '散步',
|
||||
'durationMinutes': i == 2 || i == 5 ? 0 : 30,
|
||||
'isRestDay': i == 2 || i == 5,
|
||||
'isCompleted': false,
|
||||
}),
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
/// 拍照/相册直接触发(无需跳转页面)
|
||||
final cameraActionProvider = NotifierProvider<CameraActionNotifier, String?>(CameraActionNotifier.new);
|
||||
|
||||
class CameraActionNotifier extends Notifier<String?> {
|
||||
@override String? build() => null;
|
||||
void trigger(String action) => state = action;
|
||||
void clear() => state = null;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,12 @@ class MedicationService {
|
||||
Future<void> confirm(String id) async {
|
||||
await _api.post('/api/medications/$id/confirm');
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getReminders() async {
|
||||
final res = await _api.get('/api/medications/reminders');
|
||||
final list = res.data['data'] as List? ?? [];
|
||||
return list.cast<Map<String, dynamic>>();
|
||||
}
|
||||
}
|
||||
|
||||
/// 饮食服务
|
||||
|
||||
@@ -43,16 +43,16 @@ class AgentBar extends ConsumerWidget {
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 6),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? const Color(0xFF635BFF) : Colors.white,
|
||||
border: Border.all(color: const Color(0xFF635BFF)),
|
||||
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(0xFF635BFF)),
|
||||
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(0xFF635BFF))),
|
||||
Text(label, style: TextStyle(fontSize: 13, color: isSelected ? Colors.white : const Color(0xFF8B9CF7))),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -5,7 +5,7 @@ import '../providers/auth_provider.dart';
|
||||
import '../providers/data_providers.dart';
|
||||
import '../providers/chat_provider.dart';
|
||||
|
||||
/// 侧滑抽屉——健康概览 + 历史对话 + 菜单
|
||||
/// 侧滑抽屉——彩色分区卡片式设计
|
||||
class HealthDrawer extends ConsumerWidget {
|
||||
const HealthDrawer({super.key});
|
||||
|
||||
@@ -17,207 +17,482 @@ class HealthDrawer extends ConsumerWidget {
|
||||
final conversations = ref.watch(conversationListProvider);
|
||||
|
||||
return Drawer(
|
||||
width: MediaQuery.of(context).size.width * 0.82,
|
||||
backgroundColor: const Color(0xFFFAFBFE),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 20),
|
||||
children: [
|
||||
// 用户信息
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
// ════════════ 用户区 ════════════
|
||||
_SectionCard(
|
||||
color: const Color(0xFF635BFF),
|
||||
gradientColors: [const Color(0xFF7C74FF), const Color(0xFF5248E8)],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(18),
|
||||
child: Row(children: [
|
||||
GestureDetector(
|
||||
onTap: () => pushRoute(ref, 'profile'),
|
||||
child: Container(
|
||||
width: 52, height: 52,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(colors: [Colors.white.withAlpha(40), Colors.white.withAlpha(15)]),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white30, width: 1.5),
|
||||
),
|
||||
child: user?.avatarUrl != null
|
||||
? ClipOval(child: Image.network(user!.avatarUrl!, fit: BoxFit.cover, errorBuilder: (_, e, s) => _defaultAvatar()))
|
||||
: _defaultAvatar(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(user?.name ?? '未设置昵称', style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w700, color: Colors.white)),
|
||||
const SizedBox(height: 2),
|
||||
Text(user?.phone ?? '未登录', style: TextStyle(fontSize: 12, color: Colors.white70)),
|
||||
],
|
||||
)),
|
||||
Icon(Icons.chevron_right, size: 18, color: Colors.white54),
|
||||
]),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// ════════════ 健康概览区 ════════════
|
||||
_SectionCard(
|
||||
color: const Color(0xFFE8F0FE),
|
||||
gradientColors: null,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => pushRoute(ref, 'profile'),
|
||||
child: CircleAvatar(
|
||||
radius: 28,
|
||||
backgroundColor: const Color(0xFFEDEBFF),
|
||||
child: Icon(Icons.person, size: 32, color: Theme.of(context).colorScheme.primary),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 4),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF635BFF).withAlpha(15),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(Icons.monitor_heart_rounded, size: 13, color: const Color(0xFF635BFF)),
|
||||
SizedBox(width: 4),
|
||||
Text('健康概览', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xFF635BFF))),
|
||||
]),
|
||||
),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () => pushRoute(ref, 'trend'),
|
||||
child: const Padding(padding: EdgeInsets.all(4), child: Text('详情', style: TextStyle(fontSize: 11, color: Color(0xFF888888)))),
|
||||
),
|
||||
]),
|
||||
),
|
||||
latestHealth.when(
|
||||
data: (data) => Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 12, 14),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_MetricTile(icon: Icons.favorite_rounded, label: '血压', value: _bpText(data['BloodPressure']), accentColor: const Color(0xFFFF6B6B), onTap: () => pushRoute(ref, 'trend', params: {'type': 'blood_pressure'})),
|
||||
_MetricTile(icon: Icons.monitor_heart_outlined, label: '心率', value: _metricVal(data['HeartRate']), unit: '', accentColor: const Color(0xFFFF9F43), onTap: () => pushRoute(ref, 'trend', params: {'type': 'heart_rate'})),
|
||||
_MetricTile(icon: Icons.bloodtype_outlined, label: '血糖', value: _metricVal(data['Glucose']), unit: '', accentColor: const Color(0xFF26C281), onTap: () => pushRoute(ref, 'trend', params: {'type': 'glucose'})),
|
||||
_MetricTile(icon: Icons.air_outlined, label: '血氧', value: _metricVal(data['SpO2']), unit: '%', accentColor: const Color(0xFF4D96FF), onTap: () => pushRoute(ref, 'trend', params: {'type': 'spo2'})),
|
||||
_MetricTile(icon: Icons.monitor_weight_outlined, label: '体重', value: _metricVal(data['Weight']), unit: 'kg', accentColor: const Color(0xFFA55EEA), onTap: () => pushRoute(ref, 'trend', params: {'type': 'weight'})),
|
||||
],
|
||||
),
|
||||
),
|
||||
loading: () => const Padding(padding: EdgeInsets.symmetric(vertical: 20), child: Center(child: SizedBox(width: 22, height: 22, child: CircularProgressIndicator(strokeWidth: 2, color: Color(0xFF635BFF))))),
|
||||
error: (Object err, StackTrace st) => Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 12, 14),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_MetricTile(icon: Icons.favorite_rounded, label: '血压', value: '--', accentColor: const Color(0xFFFF6B6B)),
|
||||
_MetricTile(icon: Icons.monitor_heart_outlined, label: '心率', value: '--', accentColor: const Color(0xFFFF9F43)),
|
||||
_MetricTile(icon: Icons.bloodtype_outlined, label: '血糖', value: '--', accentColor: const Color(0xFF26C281)),
|
||||
_MetricTile(icon: Icons.air_outlined, label: '血氧', value: '--', accentColor: const Color(0xFF4D96FF)),
|
||||
_MetricTile(icon: Icons.monitor_weight_outlined, label: '体重', value: '--', accentColor: const Color(0xFFA55EEA)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(user?.name ?? '未设置昵称', style: Theme.of(context).textTheme.titleMedium),
|
||||
if (user != null) const SizedBox(height: 4),
|
||||
Text(user?.phone ?? '', style: Theme.of(context).textTheme.labelMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
_DrawerItem(icon: Icons.settings, label: '设置', onTap: () => pushRoute(ref, 'settings')),
|
||||
const Divider(),
|
||||
|
||||
// 健康概览——接真实数据
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||
child: Text('健康概览', style: Theme.of(context).textTheme.labelMedium!.copyWith(fontWeight: FontWeight.w600)),
|
||||
),
|
||||
latestHealth.when(
|
||||
data: (data) => Column(children: [
|
||||
_HealthMetric(icon: Icons.favorite, label: '血压', value: _bpText(data['BloodPressure']), onTap: () => pushRoute(ref, 'trend', params: {'type': 'blood_pressure'})),
|
||||
_HealthMetric(icon: Icons.monitor_heart, label: '心率', value: _metricText(data['HeartRate'], '次/分'), onTap: () => pushRoute(ref, 'trend', params: {'type': 'heart_rate'})),
|
||||
_HealthMetric(icon: Icons.bloodtype, label: '血糖', value: _metricText(data['Glucose'], 'mmol/L'), onTap: () => pushRoute(ref, 'trend', params: {'type': 'glucose'})),
|
||||
_HealthMetric(icon: Icons.air, label: '血氧', value: _metricText(data['SpO2'], '%'), onTap: () => pushRoute(ref, 'trend', params: {'type': 'spo2'})),
|
||||
]),
|
||||
loading: () => const Padding(padding: EdgeInsets.all(16), child: Center(child: SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2)))),
|
||||
error: (_, _) => Column(children: [
|
||||
_HealthMetric(icon: Icons.favorite, label: '血压', value: '--'),
|
||||
_HealthMetric(icon: Icons.monitor_heart, label: '心率', value: '--'),
|
||||
_HealthMetric(icon: Icons.bloodtype, label: '血糖', value: '--'),
|
||||
_HealthMetric(icon: Icons.air, label: '血氧', value: '--'),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
const Divider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||
child: Row(children: [
|
||||
Text('历史对话', style: Theme.of(context).textTheme.labelMedium!.copyWith(fontWeight: FontWeight.w600)),
|
||||
const Spacer(),
|
||||
TextButton(onPressed: () => ref.invalidate(conversationListProvider), child: const Text('刷新', style: TextStyle(fontSize: 12, color: Color(0xFF635BFF)))),
|
||||
]),
|
||||
),
|
||||
Expanded(
|
||||
child: conversations.when(
|
||||
data: (items) {
|
||||
if (items.isEmpty) {
|
||||
return const Center(child: Text('暂无历史对话', style: TextStyle(color: Color(0xFF999999), fontSize: 14)));
|
||||
}
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (ctx, i) => _ConversationItem(item: items[i], ref: ref),
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator(strokeWidth: 2)),
|
||||
error: (_, __) => const Center(child: Text('加载失败', style: TextStyle(color: Color(0xFF999999), fontSize: 14))),
|
||||
// ════════════ 功能区(横向排布)════════════
|
||||
_SectionCard(
|
||||
color: const Color(0xFFFDF6EC),
|
||||
gradientColors: null,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 14, 14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF0A060).withAlpha(15),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: const Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(Icons.apps_rounded, size: 13, color: Color(0xFFF0A060)),
|
||||
SizedBox(width: 4),
|
||||
Text('功能', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xFFF0A060))),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_FeatureChip(icon: Icons.description_outlined, label: '报告管理', bgColor: const Color(0xFFFFEDE0), iconColor: const Color(0xFFF0A060), onTap: () => pushRoute(ref, 'reports')),
|
||||
_FeatureChip(icon: Icons.calendar_today_outlined, label: '健康日历', bgColor: const Color(0xFFE0F0E0), iconColor: const Color(0xFF26C281), onTap: () => pushRoute(ref, 'calendar')),
|
||||
_FeatureChip(icon: Icons.restaurant_outlined, label: '饮食记录', bgColor: const Color(0xFFFFE8E0), iconColor: const Color(0xFFFF8C42), onTap: () => pushRoute(ref, 'dietRecords')),
|
||||
_FeatureChip(icon: Icons.event_note_outlined, label: '复查随访', bgColor: const Color(0xFFE8E0FF), iconColor: const Color(0xFF8B6CF7), onTap: () => pushRoute(ref, 'followups')),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
_DrawerItem(icon: Icons.logout, label: '退出登录', onTap: () async {
|
||||
final ok = await showDialog<bool>(context: context, builder: (ctx) => AlertDialog(
|
||||
title: const Text('退出登录'), content: const Text('确定退出?'),
|
||||
actions: [TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')), TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定'))]));
|
||||
if (ok == true) { await ref.read(authProvider.notifier).logout(); goRoute(ref, 'login'); }
|
||||
}),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// ════════════ 历史对话区 ════════════
|
||||
_SectionCard(
|
||||
color: const Color(0xFFF0F4FF),
|
||||
gradientColors: null,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 4),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF4D96FF).withAlpha(15),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: const Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(Icons.history_rounded, size: 13, color: Color(0xFF4D96FF)),
|
||||
SizedBox(width: 4),
|
||||
Text('历史对话', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xFF4D96FF))),
|
||||
]),
|
||||
),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () => ref.invalidate(conversationListProvider),
|
||||
child: const Padding(padding: EdgeInsets.all(4), child: Icon(Icons.refresh, size: 15, color: Color(0xFFAAAAAA))),
|
||||
),
|
||||
]),
|
||||
),
|
||||
_buildConversationList(ref, conversations),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// ════════════ 设置区 ════════════
|
||||
_SectionCard(
|
||||
color: const Color(0xFFF5F5F7),
|
||||
gradientColors: null,
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => pushRoute(ref, 'settings'),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 14),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
width: 34, height: 34,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEEEEEE),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(Icons.settings_outlined, size: 18, color: Color(0xFF666666)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(child: Text('设置', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500, color: Color(0xFF333333)))),
|
||||
const Icon(Icons.chevron_right, size: 16, color: Color(0xFFCCCCCC)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 6),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static Widget _defaultAvatar() => const Icon(Icons.person, size: 26, color: Colors.white70);
|
||||
|
||||
String _bpText(dynamic bp) {
|
||||
if (bp == null) return '--';
|
||||
if (bp is Map) return '${bp['systolic'] ?? '--'}/${bp['diastolic'] ?? '--'}';
|
||||
return '--';
|
||||
}
|
||||
|
||||
String _metricText(dynamic metric, String unit) {
|
||||
String _metricVal(dynamic metric) {
|
||||
if (metric == null) return '--';
|
||||
if (metric is Map) {
|
||||
final v = metric['value'];
|
||||
return v != null ? '$v $unit' : '--';
|
||||
}
|
||||
return '--';
|
||||
if (metric is Map) { final v = metric['value']; return v?.toString() ?? '--'; }
|
||||
return metric.toString();
|
||||
}
|
||||
|
||||
Widget _buildConversationList(WidgetRef ref, AsyncValue<List<ConversationItem>> conversations) {
|
||||
return conversations.when(
|
||||
data: (items) {
|
||||
if (items.isEmpty) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: Text('暂无历史对话', style: TextStyle(color: Color(0xFFBBBBBB), fontSize: 13)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 6, 8, 14),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: items.map((item) => _ConversationItem(item: item)).toList(),
|
||||
),
|
||||
);
|
||||
},
|
||||
loading: () => const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Color(0xFF4D96FF)),
|
||||
),
|
||||
),
|
||||
),
|
||||
error: (Object err, StackTrace st) => const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: Text('加载失败', style: TextStyle(color: Color(0xFFBBBBBB), fontSize: 13)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DrawerItem extends StatelessWidget {
|
||||
final IconData icon; final String label; final VoidCallback onTap;
|
||||
const _DrawerItem({required this.icon, required this.label, required this.onTap});
|
||||
@override Widget build(BuildContext context) => ListTile(leading: Icon(icon, size: 20, color: const Color(0xFF666666)), title: Text(label, style: const TextStyle(fontSize: 16)), onTap: onTap, dense: true);
|
||||
}
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// 分区卡片容器 —— 带圆角、阴影和微动效
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class _HealthMetric extends StatelessWidget {
|
||||
final IconData icon; final String label; final String value; final VoidCallback? onTap;
|
||||
const _HealthMetric({required this.icon, required this.label, required this.value, this.onTap});
|
||||
@override Widget build(BuildContext context) => ListTile(
|
||||
leading: Icon(icon, size: 18, color: const Color(0xFF635BFF)),
|
||||
title: Text(label, style: const TextStyle(fontSize: 16, color: Color(0xFF1A1A1A))),
|
||||
trailing: Text(value, style: TextStyle(fontSize: 16, color: value == '--' ? const Color(0xFF999999) : const Color(0xFF1A1A1A))),
|
||||
dense: true,
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
class _SectionCard extends StatelessWidget {
|
||||
final Widget child;
|
||||
final Color color;
|
||||
final List<Color>? gradientColors;
|
||||
|
||||
class _ConversationItem extends ConsumerWidget {
|
||||
final ConversationItem item;
|
||||
final WidgetRef ref;
|
||||
const _ConversationItem({required this.item, required this.ref});
|
||||
const _SectionCard({required this.child, required this.color, this.gradientColors});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF8F7FF),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
Widget build(BuildContext context) {
|
||||
return TweenAnimationBuilder<double>(
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
duration: const Duration(milliseconds: 500),
|
||||
curve: Curves.easeOutCubic,
|
||||
builder: (context, value, child) => Transform.translate(
|
||||
offset: Offset(0, 8 * (1 - value)),
|
||||
child: Opacity(opacity: value, child: child),
|
||||
),
|
||||
child: ListTile(
|
||||
leading: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEDEBFF),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(_getAgentIcon(item.agent), size: 18, color: const Color(0xFF635BFF)),
|
||||
),
|
||||
title: Text(item.title, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
|
||||
subtitle: Text(item.lastMessage, style: TextStyle(fontSize: 12, color: Colors.grey[500])),
|
||||
trailing: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(_formatTime(item.updatedAt), style: const TextStyle(fontSize: 10, color: Color(0xFFCCCCCC))),
|
||||
const SizedBox(height: 4),
|
||||
PopupMenuButton<int>(
|
||||
icon: const Icon(Icons.more_vert, size: 16, color: Color(0xFFCCCCCC)),
|
||||
itemBuilder: (_) => [
|
||||
const PopupMenuItem(value: 1, child: Text('继续聊')),
|
||||
const PopupMenuItem(value: 2, child: Text('删除')),
|
||||
],
|
||||
onSelected: (v) async {
|
||||
if (v == 1) {
|
||||
ref.read(chatProvider.notifier).setAgent(item.agent);
|
||||
Navigator.pop(context);
|
||||
} else if (v == 2) {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('删除对话'),
|
||||
content: const Text('确定删除该对话?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')),
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定')),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ok == true) {
|
||||
ref.invalidate(conversationListProvider);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: gradientColors == null ? color : null,
|
||||
gradient: gradientColors != null ? LinearGradient(
|
||||
colors: gradientColors!,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
) : null,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: (gradientColors?.first ?? color).withAlpha(25),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
ref.read(chatProvider.notifier).setAgent(item.agent);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// 健康指标小方块
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class _MetricTile extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final String value;
|
||||
final String? unit;
|
||||
final Color accentColor;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _MetricTile({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.value,
|
||||
this.unit,
|
||||
required this.accentColor,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: ((MediaQuery.of(context).size.width * 0.82 - 48) / 3).floorToDouble(),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: accentColor.withAlpha(30)),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 28, height: 28,
|
||||
decoration: BoxDecoration(
|
||||
color: accentColor.withAlpha(15),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(icon, size: 15, color: accentColor),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(value, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w700, color: const Color(0xFF1A1A1A))),
|
||||
Text(label, style: TextStyle(fontSize: 10, color: Colors.grey[500])),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// 功能按钮(横向)
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class _FeatureChip extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final Color bgColor;
|
||||
final Color iconColor;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _FeatureChip({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.bgColor,
|
||||
required this.iconColor,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(icon, size: 17, color: iconColor),
|
||||
const SizedBox(width: 6),
|
||||
Text(label, style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500, color: iconColor.withAlpha(220))),
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// 历史对话项
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
class _ConversationItem extends StatelessWidget {
|
||||
final ConversationItem item;
|
||||
|
||||
const _ConversationItem({required this.item});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = _conversationColors(item.agent);
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: colors.$1.withAlpha(80)),
|
||||
),
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
leading: Container(
|
||||
width: 32, height: 32,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(colors: [colors.$2.withAlpha(30), colors.$2.withAlpha(15)]),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(_getAgentIcon(item.agent), size: 15, color: colors.$2),
|
||||
),
|
||||
title: Text(item.title, maxLines: 1, overflow: TextOverflow.ellipsis, style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: Color(0xFF333333))),
|
||||
subtitle: Text(item.lastMessage, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 11, color: Colors.grey[500])),
|
||||
trailing: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(_formatTime(item.updatedAt), style: TextStyle(fontSize: 9, color: Colors.grey[400])),
|
||||
const SizedBox(height: 2),
|
||||
Icon(Icons.chevron_right, size: 12, color: Colors.grey[300]),
|
||||
],
|
||||
),
|
||||
dense: true,
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
IconData _getAgentIcon(ActiveAgent agent) {
|
||||
switch (agent) {
|
||||
case ActiveAgent.health: return Icons.health_and_safety;
|
||||
case ActiveAgent.diet: return Icons.restaurant;
|
||||
case ActiveAgent.medication: return Icons.medication;
|
||||
case ActiveAgent.report: return Icons.file_open;
|
||||
case ActiveAgent.exercise: return Icons.directions_run;
|
||||
case ActiveAgent.consultation: return Icons.chat;
|
||||
default: return Icons.chat_bubble_outline;
|
||||
}
|
||||
return switch (agent) {
|
||||
ActiveAgent.health => Icons.health_and_safety_outlined,
|
||||
ActiveAgent.diet => Icons.restaurant_outlined,
|
||||
ActiveAgent.medication => Icons.medication_outlined,
|
||||
ActiveAgent.report => Icons.description_outlined,
|
||||
ActiveAgent.exercise => Icons.directions_run_outlined,
|
||||
ActiveAgent.consultation => Icons.chat_bubble_outline,
|
||||
_ => Icons.chat_bubble_outline,
|
||||
};
|
||||
}
|
||||
|
||||
String _formatTime(DateTime time) {
|
||||
@@ -229,3 +504,19 @@ class _ConversationItem extends ConsumerWidget {
|
||||
return '${time.month}/${time.day}';
|
||||
}
|
||||
}
|
||||
|
||||
(_ColorSet bg, _ColorSet accent) _conversationColors(ActiveAgent agent) {
|
||||
return switch (agent) {
|
||||
ActiveAgent.health => (const _ColorSet(0xFFE8F5E9), const _ColorSet(0xFF26C281)),
|
||||
ActiveAgent.diet => (const _ColorSet(0xFFFFF3E0), const _ColorSet(0xFFFF8C42)),
|
||||
ActiveAgent.medication => (const _ColorSet(0xFFFFEBEE), const _ColorSet(0xFFE898A8)),
|
||||
ActiveAgent.report => (const _ColorSet(0xFFEDE7F6), const _ColorSet(0xFF8B6CF7)),
|
||||
ActiveAgent.exercise => (const _ColorSet(0xFFE0F7FA), const _ColorSet(0xFF00BCD4)),
|
||||
ActiveAgent.consultation => (const _ColorSet(0xFFE3F2FD), const _ColorSet(0xFF4D96FF)),
|
||||
_ => (const _ColorSet(0xFFF5F5F5), const _ColorSet(0xFF999999)),
|
||||
};
|
||||
}
|
||||
|
||||
class _ColorSet extends Color {
|
||||
const _ColorSet(int super.value);
|
||||
}
|
||||
|
||||
BIN
微信图片_20260603102503_4528_320.jpg
Normal file
|
After Width: | Height: | Size: 602 KiB |