Files
AI-Health/health_app/lib/widgets/ble_sync_dialog.dart
MingNian 4507083f3f refactor: 重构蓝牙设备页与新增设备页的扫描-连接-录入流程
- 通用 BLE 健康设备识别(血压计/血糖仪/体重秤/血氧仪 标准 service UUID)
- 蓝牙设备页静默自动同步:仅匹配已绑定的设备名+类型,收到数据后变绿
- 新增设备页:扫描所有支持类型设备 → 选连接 → 绑定 + 同步首次数据
- 修复 read 缓存导致的重复录入循环(删除主动 read,依赖 indicate 推送)
- 修复 isConnected 缓存状态导致连接异常(强制先 disconnect 再 connect)
- 录入弹窗:血压心率同等级展示、3 秒自动关闭/手动确认
- 顺手更新本机开发 IP 与清理过时设计文档
2026-06-28 22:53:35 +08:00

161 lines
4.5 KiB
Dart

import 'package:flutter/material.dart';
import '../core/app_colors.dart';
import '../models/bp_reading.dart';
Future<void> showBleSyncDialog(
BuildContext context, {
required BpReading reading,
}) {
return showDialog<void>(
context: context,
barrierDismissible: false,
barrierColor: Colors.black.withValues(alpha: 0.54),
builder: (ctx) => Dialog(
insetPadding: const EdgeInsets.symmetric(horizontal: 28),
backgroundColor: Colors.transparent,
child: Container(
width: double.infinity,
constraints: const BoxConstraints(maxWidth: 380),
padding: const EdgeInsets.fromLTRB(22, 28, 22, 22),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(28),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.14),
blurRadius: 34,
offset: const Offset(0, 18),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'数据已录入',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w900,
color: AppColors.textPrimary,
),
),
const SizedBox(height: 24),
Row(
children: [
Expanded(
child: _MetricCard(
label: '收缩压',
value: '${reading.systolic}',
unit: 'mmHg',
),
),
const SizedBox(width: 16),
Expanded(
child: _MetricCard(
label: '舒张压',
value: '${reading.diastolic}',
unit: 'mmHg',
),
),
],
),
if (reading.pulse != null) ...[
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: _MetricCard(
label: '脉搏',
value: '${reading.pulse}',
unit: 'bpm',
),
),
const Expanded(child: SizedBox.shrink()),
],
),
],
const SizedBox(height: 28),
GestureDetector(
onTap: () => Navigator.pop(ctx),
child: Container(
height: 50,
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: AppColors.doctorGradient,
borderRadius: BorderRadius.circular(18),
boxShadow: AppColors.buttonShadow,
),
child: const Text(
'知道了',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w900,
),
),
),
),
],
),
),
),
);
}
class _MetricCard extends StatelessWidget {
final String label;
final String value;
final String unit;
const _MetricCard({
required this.label,
required this.value,
required this.unit,
});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 16),
decoration: BoxDecoration(
color: const Color(0xFFF8FAFC),
borderRadius: BorderRadius.circular(14),
),
child: Column(
children: [
Text(
value,
style: const TextStyle(
fontSize: 36,
fontWeight: FontWeight.w900,
color: AppColors.textPrimary,
height: 1,
),
),
const SizedBox(height: 6),
Text(
unit,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: AppColors.textHint,
),
),
const SizedBox(height: 4),
Text(
label,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: AppColors.textSecondary,
),
),
],
),
);
}
}