feat: 通知推送/免打扰偏好 + 饮食记录侧滑删除修复 + 聊天交互优化
- 通知: 新增推送开关/免打扰时段偏好持久化 + EF 迁移; 通知管线支持免打扰过滤 - 饮食: 侧滑删除 confirmDismiss 按方向放行(修复删不掉); 新增 diet_nutrition_widgets; 饮食录入页重构 - 聊天: 智能体胶囊点击锁防误触; 流式状态 select 优化; 卡片入场动画 - 主页: 消息列表提取 _HomeMessages + 侧滑手势打开抽屉 - 其他: api_client IP 适配; 通知/用药/饮食端点微调; 测试更新
This commit is contained in:
@@ -12,6 +12,7 @@ import '../widgets/common_widgets.dart';
|
||||
import '../widgets/app_error_state.dart';
|
||||
import '../widgets/app_future_view.dart';
|
||||
import '../widgets/app_toast.dart';
|
||||
import 'diet/diet_nutrition_widgets.dart';
|
||||
import 'diet/diet_record_logic.dart';
|
||||
|
||||
/// 饮食记录列表(趋势+日历+胶囊详情+侧滑编辑删除)
|
||||
@@ -44,9 +45,19 @@ class _DietRecordListPageState extends ConsumerState<DietRecordListPage> {
|
||||
}
|
||||
|
||||
Future<void> _delete(String id) async {
|
||||
await ref.read(dietServiceProvider).deleteRecord(id);
|
||||
if (mounted) {
|
||||
setState(() => _data.removeWhere((d) => d['id']?.toString() == id));
|
||||
final index = _data.indexWhere((d) => d['id']?.toString() == id);
|
||||
if (index < 0) return;
|
||||
final removed = _data[index];
|
||||
setState(() => _data.removeAt(index));
|
||||
try {
|
||||
await ref.read(dietServiceProvider).deleteRecord(id);
|
||||
if (mounted) {
|
||||
AppToast.show(context, '已删除', type: AppToastType.success);
|
||||
}
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
setState(() => _data.insert(index.clamp(0, _data.length), removed));
|
||||
AppToast.show(context, '删除失败,请稍后重试', type: AppToastType.error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,16 +206,16 @@ class _DietRecordListPageState extends ConsumerState<DietRecordListPage> {
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
gradient: isSel ? AppColors.dietGradient : null,
|
||||
gradient: isSel ? DietPalette.gradient : null,
|
||||
color: isSel
|
||||
? null
|
||||
: (isToday ? AppColors.dietLight : Colors.white),
|
||||
: (isToday ? DietPalette.primarySoft : Colors.white),
|
||||
borderRadius: AppRadius.mdBorder,
|
||||
border: Border.all(
|
||||
color: isSel
|
||||
? Colors.transparent
|
||||
: (isToday
|
||||
? AppColors.dietBorder
|
||||
? const Color(0xFFC9D0FF)
|
||||
: AppColors.borderLight),
|
||||
),
|
||||
boxShadow: isSel ? AppColors.cardShadowLight : null,
|
||||
@@ -220,7 +231,7 @@ class _DietRecordListPageState extends ConsumerState<DietRecordListPage> {
|
||||
: ['一', '二', '三', '四', '五', '六', '日'][d.weekday -
|
||||
1],
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: isSel ? Colors.white : AppColors.textHint,
|
||||
),
|
||||
@@ -240,7 +251,8 @@ class _DietRecordListPageState extends ConsumerState<DietRecordListPage> {
|
||||
Text(
|
||||
'$cal',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isSel ? Colors.white70 : AppColors.textHint,
|
||||
),
|
||||
),
|
||||
@@ -280,6 +292,7 @@ class _DietRecordListPageState extends ConsumerState<DietRecordListPage> {
|
||||
final id = record['id']?.toString() ?? '';
|
||||
|
||||
return _SwipeAction(
|
||||
itemKey: ValueKey(id),
|
||||
onEdit: () => _showEditDialog(id, cal),
|
||||
onDelete: () => _delete(id),
|
||||
child: Material(
|
||||
@@ -296,10 +309,14 @@ class _DietRecordListPageState extends ConsumerState<DietRecordListPage> {
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.dietLight,
|
||||
color: DietPalette.primarySoft,
|
||||
borderRadius: AppRadius.smBorder,
|
||||
),
|
||||
child: Icon(mealIcon, size: 19, color: AppColors.diet),
|
||||
child: Icon(
|
||||
mealIcon,
|
||||
size: 19,
|
||||
color: DietPalette.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
@@ -311,7 +328,7 @@ class _DietRecordListPageState extends ConsumerState<DietRecordListPage> {
|
||||
Text(
|
||||
mealLabel,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
@@ -320,7 +337,8 @@ class _DietRecordListPageState extends ConsumerState<DietRecordListPage> {
|
||||
Text(
|
||||
'$cal 千卡',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
@@ -332,7 +350,8 @@ class _DietRecordListPageState extends ConsumerState<DietRecordListPage> {
|
||||
child: Text(
|
||||
items.map((f) => f['name']).join(' · '),
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
maxLines: 1,
|
||||
@@ -412,7 +431,7 @@ class _DietDaySummary extends StatelessWidget {
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFFFFF8DB), Color(0xFFFFFFFF)],
|
||||
colors: [Color(0xFFF0F3FF), Color(0xFFFFFFFF)],
|
||||
),
|
||||
borderRadius: AppRadius.xlBorder,
|
||||
boxShadow: AppColors.cardShadowLight,
|
||||
@@ -447,7 +466,7 @@ class _DietDaySummary extends StatelessWidget {
|
||||
width: 42,
|
||||
height: 42,
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.dietGradient,
|
||||
gradient: DietPalette.gradient,
|
||||
borderRadius: AppRadius.mdBorder,
|
||||
),
|
||||
child: const Icon(
|
||||
@@ -543,7 +562,7 @@ class _Toggle extends StatelessWidget {
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
gradient: a ? AppColors.dietGradient : null,
|
||||
gradient: a ? DietPalette.gradient : null,
|
||||
color: a ? null : Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: a ? Colors.transparent : AppColors.border),
|
||||
@@ -599,7 +618,7 @@ class _TrendChart extends StatelessWidget {
|
||||
Container(
|
||||
height: h,
|
||||
decoration: BoxDecoration(
|
||||
gradient: data[i] > 0 ? AppColors.dietGradient : null,
|
||||
gradient: data[i] > 0 ? DietPalette.gradient : null,
|
||||
color: data[i] > 0 ? null : AppColors.border,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
@@ -614,20 +633,25 @@ class _TrendChart extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _SwipeAction extends StatelessWidget {
|
||||
final Key itemKey;
|
||||
final Widget child;
|
||||
final VoidCallback onEdit;
|
||||
final VoidCallback onDelete;
|
||||
const _SwipeAction({
|
||||
required this.itemKey,
|
||||
required this.child,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
});
|
||||
@override
|
||||
Widget build(BuildContext c) => Dismissible(
|
||||
key: UniqueKey(),
|
||||
key: itemKey,
|
||||
direction: DismissDirection.endToStart,
|
||||
confirmDismiss: (_) async {
|
||||
return false;
|
||||
confirmDismiss: (direction) async {
|
||||
// 右滑编辑:不消除,弹回,编辑由 onUpdate 触发
|
||||
if (direction == DismissDirection.startToEnd) return false;
|
||||
// 左滑删除:放行,onDismissed 会触发 onDelete
|
||||
return true;
|
||||
},
|
||||
background: Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -703,11 +727,7 @@ class DietRecordDetailPage extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 15),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFFFFF9E8), Colors.white],
|
||||
),
|
||||
color: Colors.white,
|
||||
borderRadius: AppRadius.xlBorder,
|
||||
boxShadow: AppColors.cardShadowLight,
|
||||
),
|
||||
@@ -716,20 +736,6 @@ class DietRecordDetailPage extends ConsumerWidget {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.dietGradient,
|
||||
borderRadius: AppRadius.mdBorder,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.restaurant_menu,
|
||||
size: 21,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -752,25 +758,39 @@ class DietRecordDetailPage extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'$totalCal 千卡',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Color(0xFF9A3412),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_DietDetailMetric(label: '蛋白质', value: '$protein g'),
|
||||
_DietDetailMetric(label: '碳水', value: '$carbs g'),
|
||||
_DietDetailMetric(label: '脂肪', value: '$fat g'),
|
||||
_DietDetailMetric(
|
||||
label: '食物',
|
||||
value: '${items.length} 种',
|
||||
DietCalorieRing(calories: totalCal),
|
||||
const SizedBox(width: 20),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
DietMacroBar(
|
||||
label: '蛋白质',
|
||||
value: protein,
|
||||
color: DietPalette.protein,
|
||||
reference: 50,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
DietMacroBar(
|
||||
label: '碳水',
|
||||
value: carbs,
|
||||
color: DietPalette.carbs,
|
||||
reference: 100,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
DietMacroBar(
|
||||
label: '脂肪',
|
||||
value: fat,
|
||||
color: DietPalette.fat,
|
||||
reference: 35,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -783,14 +803,7 @@ class DietRecordDetailPage extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Text(
|
||||
'识别结果',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const Text('识别结果', style: AppTextStyles.sectionTitle),
|
||||
const SizedBox(height: 8),
|
||||
ClipRRect(
|
||||
borderRadius: AppRadius.xlBorder,
|
||||
@@ -810,8 +823,8 @@ class DietRecordDetailPage extends ConsumerWidget {
|
||||
child: Text(
|
||||
items[i]['name']?.toString() ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
@@ -822,7 +835,7 @@ class DietRecordDetailPage extends ConsumerWidget {
|
||||
items[i]['portion']?.toString() ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
@@ -834,9 +847,9 @@ class DietRecordDetailPage extends ConsumerWidget {
|
||||
'${items[i]['calories'] ?? 0} 千卡',
|
||||
textAlign: TextAlign.right,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF9A3412),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: DietPalette.calorie,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -865,35 +878,6 @@ class DietRecordDetailPage extends ConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _DietDetailMetric extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
const _DietDetailMetric({required this.label, required this.value});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 12, color: AppColors.textHint),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 运动计划列表(含打卡)
|
||||
class ExercisePlanPage extends ConsumerStatefulWidget {
|
||||
const ExercisePlanPage({super.key});
|
||||
|
||||
Reference in New Issue
Block a user