fix: VLM 参数优化 - temperature 0.7, top_p 0.8, 指令放 system+user
- VisionAsync 新增 Temperature=0.7, TopP=0.8 - system prompt 用专业营养识别指令 - userText 用简短"请看图识别食物"配合图片 - 修复重复 prompt 导致 VLM 误读文本的 bug
This commit is contained in:
216
health_app/lib/pages/settings/notification_prefs_page.dart
Normal file
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(0xFFF8F7FF),
|
||||
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(0xFF635BFF),
|
||||
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(0xFF635BFF), 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(0xFF635BFF)))]),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -3,65 +3,77 @@ 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(0xFFF8F7FF),
|
||||
body: SafeArea(child: SingleChildScrollView(padding: const EdgeInsets.only(bottom: 30), 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: 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: 12),
|
||||
_SetItem(icon: Icons.notifications_outlined, title: '消息通知', onTap: () => pushRoute(ref, 'notificationPrefs')),
|
||||
_SetItem(icon: Icons.medication_outlined, title: '用药提醒', subtitle: 'mmHg / mmol/L'),
|
||||
_SetItem(icon: Icons.data_usage_outlined, title: '数据导出'),
|
||||
_SetItem(icon: Icons.text_fields_outlined, title: '字体大小', trailingText: 'v1.0.0'),
|
||||
_SetItem(icon: Icons.cleaning_services_outlined, title: '清除缓存', subtitle: '73.2 MB'),
|
||||
_SetItem(icon: Icons.info_outline, title: '关于健康管家'),
|
||||
_SetItem(icon: Icons.shield_outlined, title: '隐私协议'),
|
||||
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(0xFFF5F3FF), borderRadius: BorderRadius.circular(10)), child: Icon(icon, size: 18, color: const Color(0xFF635BFF))),
|
||||
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]),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user