fix: 管理员系统 + 注册流程重构 + UI改版 + 全链路修复

- 新增管理员角色(手机号12345678910),管理员可增删医生、查看患者
- 注册页重构:去掉角色选择+审核码,改为选医生+填姓名
- 医生端点按DoctorId过滤患者,Patient↔Doctor关系建立
- Doctor/DoctorProfile/User实体新增关联字段
- JSON循环引用修复(IgnoreCycles)
- /api/doctors改为公开接口
- 登录闪屏修复+原生Android启动页
- 输入框全局白底+灰框
- 蓝牙重连同步修复
- Web端(doctor_web+health_app/web)全部删除
- 全局UI改版:白底企业风,新配色和组件系统
- 新品牌图标和启动图
This commit is contained in:
MingNian
2026-06-16 15:16:44 +08:00
parent b635e9d25f
commit c70d5d4be6
103 changed files with 12284 additions and 13049 deletions

View File

@@ -3,40 +3,60 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/app_colors.dart';
import '../../core/navigation_provider.dart';
import '../../providers/omron_device_provider.dart';
import '../../services/omron_ble_service.dart';
class DeviceManagementPage extends ConsumerStatefulWidget {
const DeviceManagementPage({super.key});
@override ConsumerState<DeviceManagementPage> createState() => _DeviceManagementPageState();
@override
ConsumerState<DeviceManagementPage> createState() =>
_DeviceManagementPageState();
}
class _DeviceManagementPageState extends ConsumerState<DeviceManagementPage> {
bool _reconnecting = false;
OverlayEntry? _toast;
@override void dispose() { _hideToast(); super.dispose(); }
@override
void dispose() {
_hideToast();
super.dispose();
}
void _showToast(String msg, {bool success = false}) {
_hideToast();
_toast = OverlayEntry(
builder: (_) => Positioned(
top: MediaQuery.of(context).padding.top + 8, left: 16, right: 16,
top: MediaQuery.of(context).padding.top + 8,
left: 16,
right: 16,
child: TweenAnimationBuilder<double>(
tween: Tween(begin: 0.0, end: 1.0), duration: const Duration(milliseconds: 250),
builder: (_, v, __) => Opacity(
tween: Tween(begin: 0.0, end: 1.0),
duration: const Duration(milliseconds: 250),
builder: (context, v, child) => Opacity(
opacity: v,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: success ? const Color(0xFF059669) : const Color(0xFFDC2626),
color: success ? AppColors.success : AppColors.error,
borderRadius: BorderRadius.circular(24),
boxShadow: const [BoxShadow(color: Colors.black26, blurRadius: 8, offset: Offset(0, 2))],
boxShadow: AppColors.cardShadow,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
success ? Icons.check_circle : Icons.info_outline,
color: Colors.white,
size: 18,
),
const SizedBox(width: 8),
Expanded(
child: Text(
msg,
style: const TextStyle(color: Colors.white, fontSize: 14),
),
),
],
),
child: Row(mainAxisSize: MainAxisSize.min, children: [
Icon(success ? Icons.check_circle : Icons.info_outline, color: Colors.white, size: 18),
const SizedBox(width: 8),
Expanded(child: Text(msg, style: const TextStyle(color: Colors.white, fontSize: 14))),
]),
),
),
),
@@ -46,7 +66,10 @@ class _DeviceManagementPageState extends ConsumerState<DeviceManagementPage> {
Future.delayed(const Duration(seconds: 2), _hideToast);
}
void _hideToast() { _toast?.remove(); _toast = null; }
void _hideToast() {
_toast?.remove();
_toast = null;
}
Future<void> _reconnect(String mac) async {
if (_reconnecting) return;
@@ -61,15 +84,18 @@ class _DeviceManagementPageState extends ConsumerState<DeviceManagementPage> {
}
}
@override Widget build(BuildContext context) {
@override
Widget build(BuildContext context) {
final device = ref.watch(omronDeviceProvider);
return Scaffold(
backgroundColor: const Color(0xFFF5F5F5),
backgroundColor: AppColors.background,
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
title: const Text('蓝牙设备', style: TextStyle(color: AppColors.textPrimary)),
title: const Text('蓝牙设备'),
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () => popRoute(ref),
),
actions: [
IconButton(
icon: const Icon(Icons.add, color: AppColors.primary),
@@ -85,139 +111,279 @@ class _DeviceManagementPageState extends ConsumerState<DeviceManagementPage> {
Widget _buildEmpty() => Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(mainAxisSize: MainAxisSize.min, children: [
Container(
width: 80, height: 80,
decoration: BoxDecoration(color: const Color(0xFFF0F0F0), borderRadius: BorderRadius.circular(24)),
child: const Icon(Icons.bluetooth_disabled, size: 40, color: Color(0xFFBBBBBB)),
),
const SizedBox(height: 16),
const Text('暂无设备', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: AppColors.textPrimary)),
const SizedBox(height: 6),
const Text('点击右上角 + 添加血压计', style: TextStyle(fontSize: 14, color: AppColors.textHint)),
]),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 82,
height: 82,
decoration: BoxDecoration(
color: AppColors.iconBg,
borderRadius: BorderRadius.circular(24),
border: Border.all(color: AppColors.border),
),
child: const Icon(
Icons.bluetooth_disabled,
size: 40,
color: AppColors.primary,
),
),
const SizedBox(height: 16),
const Text(
'暂无设备',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: AppColors.textPrimary,
),
),
const SizedBox(height: 6),
const Text(
'点击右上角 + 添加血压计',
style: TextStyle(fontSize: 14, color: AppColors.textSecondary),
),
],
),
),
);
Widget _buildDeviceList(DeviceBindState d) => ListView(
padding: const EdgeInsets.all(16),
children: [
// 设备卡片
GestureDetector(
onTap: d.isConnected ? null : () => _reconnect(d.mac ?? ''),
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
duration: const Duration(milliseconds: 250),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(18),
border: Border.all(
color: d.isConnected ? const Color(0xFF10B981) : const Color(0xFFEEEEEE),
width: d.isConnected ? 1.5 : 1,
color: d.isConnected ? AppColors.success : AppColors.border,
),
boxShadow: AppColors.cardShadowLight,
),
child: Row(children: [
Container(
width: 48, height: 48,
decoration: BoxDecoration(
color: d.isConnected ? const Color(0xFFD1FAE5) : const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(14),
),
child: Icon(Icons.bluetooth, size: 24,
color: d.isConnected ? const Color(0xFF10B981) : const Color(0xFFBBBBBB)),
),
const SizedBox(width: 14),
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(d.name ?? '血压计', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: AppColors.textPrimary)),
const SizedBox(height: 2),
Text(d.mac ?? '', style: const TextStyle(fontSize: 12, color: AppColors.textHint)),
if (d.lastSync != null)
Text('上次同步: ${d.lastSync}', style: const TextStyle(fontSize: 11, color: AppColors.textHint)),
])),
if (_reconnecting)
const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2))
else ...[
child: Row(
children: [
Container(
width: 8, height: 8,
width: 50,
height: 50,
decoration: BoxDecoration(
color: d.isConnected ? const Color(0xFF10B981) : const Color(0xFFBBBBBB),
shape: BoxShape.circle,
boxShadow: d.isConnected ? [BoxShadow(color: const Color(0xFF10B981).withOpacity(0.4), blurRadius: 4)] : null,
color: d.isConnected
? AppColors.successLight
: AppColors.cardInner,
borderRadius: BorderRadius.circular(15),
),
child: Icon(
Icons.bluetooth,
size: 24,
color: d.isConnected ? AppColors.success : AppColors.textHint,
),
),
const SizedBox(width: 8),
Text(
d.isConnected ? '已连接' : '未连接',
style: TextStyle(fontSize: 13, color: d.isConnected ? const Color(0xFF10B981) : AppColors.textHint),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
d.name ?? '血压计',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w800,
color: AppColors.textPrimary,
),
),
const SizedBox(height: 2),
Text(
d.mac ?? '',
style: const TextStyle(
fontSize: 12,
color: AppColors.textHint,
),
),
if (d.lastSync != null)
Text(
'上次同步: ${d.lastSync}',
style: const TextStyle(
fontSize: 11,
color: AppColors.textHint,
),
),
],
),
),
if (_reconnecting)
const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 2),
)
else ...[
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
color: d.isConnected
? AppColors.success
: AppColors.textHint,
shape: BoxShape.circle,
),
),
const SizedBox(width: 8),
Text(
d.isConnected ? '已连接' : '未连接',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: d.isConnected
? AppColors.success
: AppColors.textHint,
),
),
],
],
]),
),
),
),
// 最近读数
if (d.lastReading != null) ...[
const SizedBox(height: 12),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16)),
child: Row(children: [
const Text('最近测量', style: TextStyle(fontSize: 14, color: AppColors.textHint)),
const Spacer(),
Text(d.lastReading!.display, style: const TextStyle(fontSize: 24, fontWeight: FontWeight.w700, color: AppColors.textPrimary)),
const SizedBox(width: 4),
const Text('mmHg', style: TextStyle(fontSize: 12, color: AppColors.textHint)),
if (d.lastReading!.pulse != null) ...[
const SizedBox(width: 16),
Text('${d.lastReading!.pulse} bpm', style: const TextStyle(fontSize: 14, color: AppColors.primary)),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(18),
border: Border.all(color: AppColors.border),
boxShadow: AppColors.cardShadowLight,
),
child: Row(
children: [
const Text(
'最近测量',
style: TextStyle(fontSize: 14, color: AppColors.textSecondary),
),
const Spacer(),
Text(
d.lastReading!.display,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.w900,
color: AppColors.textPrimary,
),
),
const SizedBox(width: 4),
const Text(
'mmHg',
style: TextStyle(fontSize: 12, color: AppColors.textHint),
),
if (d.lastReading!.pulse != null) ...[
const SizedBox(width: 16),
Text(
'${d.lastReading!.pulse} bpm',
style: const TextStyle(
fontSize: 14,
color: AppColors.primary,
fontWeight: FontWeight.w700,
),
),
],
],
]),
),
),
],
const SizedBox(height: 16),
// 解绑
SizedBox(width: double.infinity, child: OutlinedButton(
onPressed: () 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('确定'), style: TextButton.styleFrom(foregroundColor: AppColors.error)),
],
));
if (ok == true) await ref.read(omronDeviceProvider.notifier).unbind();
},
style: OutlinedButton.styleFrom(
foregroundColor: AppColors.error, side: const BorderSide(color: Color(0xFFFECACA)),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
padding: const EdgeInsets.symmetric(vertical: 12),
SizedBox(
width: double.infinity,
child: OutlinedButton(
onPressed: () 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),
style: TextButton.styleFrom(
foregroundColor: AppColors.error,
),
child: const Text('确定'),
),
],
),
);
if (ok == true) {
await ref.read(omronDeviceProvider.notifier).unbind();
}
},
style: OutlinedButton.styleFrom(
foregroundColor: AppColors.error,
side: const BorderSide(color: AppColors.errorLight),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
padding: const EdgeInsets.symmetric(vertical: 12),
),
child: const Text('解绑设备'),
),
child: const Text('解绑设备'),
)),
),
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16)),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const Text('使用说明', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
const SizedBox(height: 8),
_tip('1', '血压计装好电池,绑好袖带'),
_tip('2', '按开始键测量,结束后设备自动进入通信模式'),
_tip('3', '点击设备栏即可自动连接并同步数据'),
]),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(18),
border: Border.all(color: AppColors.border),
boxShadow: AppColors.cardShadowLight,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'使用说明',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w800,
color: AppColors.textPrimary,
),
),
const SizedBox(height: 8),
_tip('1', '血压计装好电池,绑好袖带'),
_tip('2', '按开始键测量,结束后设备自动进入通信模式'),
_tip('3', '点击设备卡片即可自动连接并同步数据'),
],
),
),
],
);
Widget _tip(String n, String t) => Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text('$n.', style: const TextStyle(fontSize: 13, color: AppColors.primary, fontWeight: FontWeight.w600)),
const SizedBox(width: 4),
Expanded(child: Text(t, style: const TextStyle(fontSize: 13, color: AppColors.textSecondary))),
]),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'$n.',
style: const TextStyle(
fontSize: 13,
color: AppColors.primary,
fontWeight: FontWeight.w800,
),
),
const SizedBox(width: 4),
Expanded(
child: Text(
t,
style: const TextStyle(
fontSize: 13,
color: AppColors.textSecondary,
),
),
),
],
),
);
}

View File

@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:permission_handler/permission_handler.dart';
@@ -13,7 +12,8 @@ import '../../services/omron_ble_service.dart';
class DeviceScanPage extends ConsumerStatefulWidget {
const DeviceScanPage({super.key});
@override ConsumerState<DeviceScanPage> createState() => _DeviceScanPageState();
@override
ConsumerState<DeviceScanPage> createState() => _DeviceScanPageState();
}
class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
@@ -33,21 +33,32 @@ class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
late AnimationController _pulseCtrl;
late Animation<double> _pulseAnim;
@override void initState() {
@override
void initState() {
super.initState();
_pulseCtrl = AnimationController(vsync: this, duration: const Duration(milliseconds: 1200));
_pulseAnim = Tween(begin: 0.8, end: 1.4).animate(CurvedAnimation(parent: _pulseCtrl, curve: Curves.easeInOut));
_pulseCtrl = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1200),
);
_pulseAnim = Tween(
begin: 0.8,
end: 1.4,
).animate(CurvedAnimation(parent: _pulseCtrl, curve: Curves.easeInOut));
_pulseCtrl.repeat(reverse: true);
_scanSub = FlutterBluePlus.scanResults.listen((list) {
if (!mounted) return;
final bpList = list.where((r) => OmronBleService.isBpDevice(r)).toList();
setState(() { _results.clear(); _results.addAll(bpList); });
setState(() {
_results.clear();
_results.addAll(bpList);
});
});
_start();
}
@override void dispose() {
@override
void dispose() {
_pulseCtrl.dispose();
_scanSub?.cancel();
_readingSub?.cancel();
@@ -57,7 +68,10 @@ class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
}
Future<void> _start() async {
setState(() { _scanning = true; _connected = false; });
setState(() {
_scanning = true;
_connected = false;
});
_results.clear();
await [Permission.bluetoothScan, Permission.bluetoothConnect].request();
@@ -66,17 +80,24 @@ class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
final locStatus = await Permission.locationWhenInUse.serviceStatus;
if (locStatus != ServiceStatus.enabled && mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('请先打开GPS定位否则无法扫描蓝牙'), backgroundColor: AppColors.warning),
const SnackBar(
content: Text('请先打开GPS定位否则无法扫描蓝牙'),
backgroundColor: AppColors.warning,
),
);
}
}
final adapterState = await FlutterBluePlus.adapterState.first;
if (adapterState != BluetoothAdapterState.on) {
try { await FlutterBluePlus.turnOn(); } catch (_) {}
try {
await FlutterBluePlus.turnOn();
} catch (_) {}
}
try { await FlutterBluePlus.stopScan(); } catch (_) {}
try {
await FlutterBluePlus.stopScan();
} catch (_) {}
await FlutterBluePlus.startScan(
timeout: const Duration(seconds: 30),
androidScanMode: AndroidScanMode.lowLatency,
@@ -100,7 +121,9 @@ class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
? r.advertisementData.localName
: (r.device.platformName.isNotEmpty ? r.device.platformName : '血压计');
await ref.read(omronDeviceProvider.notifier).bind(r.device.remoteId.toString(), name);
await ref
.read(omronDeviceProvider.notifier)
.bind(r.device.remoteId.toString(), name);
_bleConnSub = r.device.connectionState.listen((s) {
if (s == BluetoothConnectionState.disconnected && mounted) {
@@ -109,7 +132,9 @@ class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
if (_readingReceived) {
popRoute(ref);
} else {
setState(() { _connected = false; });
setState(() {
_connected = false;
});
_start();
}
}
@@ -125,9 +150,13 @@ class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
_pulse = reading.pulse;
});
try {
await ref.read(apiClientProvider).post('/api/health-records', data: reading.toHealthRecord());
await ref
.read(apiClientProvider)
.post('/api/health-records', data: reading.toHealthRecord());
await ref.read(omronDeviceProvider.notifier).onReading(reading);
} catch (e) { debugPrint('[PAGE] 上报失败: $e'); }
} catch (e) {
debugPrint('[PAGE] 上报失败: $e');
}
Future.delayed(const Duration(milliseconds: 1500), () {
if (mounted) popRoute(ref);
});
@@ -152,13 +181,17 @@ class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
}
}
@override Widget build(BuildContext context) {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
title: Text(_connected ? _deviceName : '添加设备', style: const TextStyle(color: AppColors.textPrimary)),
title: Text(
_connected ? _deviceName : '添加设备',
style: const TextStyle(color: AppColors.textPrimary),
),
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: AppColors.textPrimary),
onPressed: () {
@@ -172,126 +205,243 @@ class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
}
// ── 扫描视图 ──
Widget _buildScan() => Column(children: [
if (_scanning && _results.isEmpty) Expanded(child: _buildScanningCenter()),
if (!_scanning && _results.isEmpty) Expanded(child: _buildScanningCenter()),
if (_results.isNotEmpty)
Expanded(
child: ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: _results.length,
itemBuilder: (_, i) => _buildTile(_results[i]),
),
),
if (!_scanning)
Padding(
padding: const EdgeInsets.all(16),
child: SizedBox(width: double.infinity, child: OutlinedButton.icon(
onPressed: _start,
icon: const Icon(Icons.refresh),
label: const Text('重新扫描'),
style: OutlinedButton.styleFrom(
foregroundColor: AppColors.primary,
side: const BorderSide(color: Color(0xFFE5E7EB)),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
padding: const EdgeInsets.symmetric(vertical: 14),
Widget _buildScan() => Column(
children: [
if (_scanning && _results.isEmpty)
Expanded(child: _buildScanningCenter()),
if (!_scanning && _results.isEmpty)
Expanded(child: _buildScanningCenter()),
if (_results.isNotEmpty)
Expanded(
child: ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: _results.length,
itemBuilder: (_, i) => _buildTile(_results[i]),
),
)),
),
]);
Widget _buildScanningCenter() => Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Stack(alignment: Alignment.center, children: [
AnimatedBuilder(
animation: _pulseAnim,
builder: (_, child) => Container(
width: 80 * _pulseAnim.value, height: 80 * _pulseAnim.value,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: AppColors.primary.withOpacity(0.08),
),
if (!_scanning)
Padding(
padding: const EdgeInsets.all(16),
child: SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: _start,
icon: const Icon(Icons.refresh),
label: const Text('重新扫描'),
style: OutlinedButton.styleFrom(
foregroundColor: AppColors.primary,
side: const BorderSide(color: AppColors.border),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
padding: const EdgeInsets.symmetric(vertical: 14),
),
),
),
),
Container(
width: 64, height: 64,
decoration: BoxDecoration(
color: const Color(0xFFF0F0FF), borderRadius: BorderRadius.circular(20),
),
child: const Icon(Icons.bluetooth_searching, size: 32, color: AppColors.primary),
],
);
Widget _buildScanningCenter() => Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
alignment: Alignment.center,
children: [
AnimatedBuilder(
animation: _pulseAnim,
builder: (_, child) => Container(
width: 80 * _pulseAnim.value,
height: 80 * _pulseAnim.value,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: AppColors.primary.withValues(alpha: 0.08),
),
),
),
Container(
width: 64,
height: 64,
decoration: BoxDecoration(
color: AppColors.avatarBg,
borderRadius: BorderRadius.circular(20),
),
child: const Icon(
Icons.bluetooth_searching,
size: 32,
color: AppColors.primary,
),
),
],
),
]),
const SizedBox(height: 20),
Text(_scanning ? '正在搜索蓝牙设备...' : '未发现设备', style: const TextStyle(fontSize: 16, color: AppColors.textHint)),
const SizedBox(height: 8),
Text(_scanning ? '请确保血压计处于通信模式' : '点击下方按钮重新搜索', style: const TextStyle(fontSize: 13, color: Color(0xFFCCCCCC))),
]),
const SizedBox(height: 20),
Text(
_scanning ? '正在搜索蓝牙设备...' : '未发现设备',
style: const TextStyle(fontSize: 16, color: AppColors.textHint),
),
const SizedBox(height: 8),
Text(
_scanning ? '请确保血压计处于通信模式' : '点击下方按钮重新搜索',
style: const TextStyle(fontSize: 13, color: Color(0xFFCCCCCC)),
),
],
),
);
// ── 已连接视图 ──
Widget _buildConnected() => Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(mainAxisSize: MainAxisSize.min, children: [
AnimatedContainer(
duration: const Duration(milliseconds: 500),
width: 100, height: 100,
decoration: BoxDecoration(
color: _readingReceived ? const Color(0xFFD1FAE5) : const Color(0xFFF0F0FF),
borderRadius: BorderRadius.circular(32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
AnimatedContainer(
duration: const Duration(milliseconds: 500),
width: 100,
height: 100,
decoration: BoxDecoration(
color: _readingReceived
? AppColors.successLight
: AppColors.avatarBg,
borderRadius: BorderRadius.circular(32),
),
child: Icon(
_readingReceived
? Icons.check_rounded
: Icons.bluetooth_connected,
size: 48,
color: _readingReceived
? const Color(0xFF10B981)
: AppColors.primary,
),
),
child: Icon(
_readingReceived ? Icons.check_rounded : Icons.bluetooth_connected,
size: 48,
color: _readingReceived ? const Color(0xFF10B981) : AppColors.primary,
const SizedBox(height: 24),
Text(
_readingReceived ? '测量完成' : '设备已连接',
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.w700,
color: AppColors.textPrimary,
),
),
),
const SizedBox(height: 24),
Text(_readingReceived ? '测量完成' : '设备已连接', style: const TextStyle(fontSize: 22, fontWeight: FontWeight.w700, color: AppColors.textPrimary)),
const SizedBox(height: 8),
const SizedBox(height: 8),
if (_readingReceived) ...[
Row(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.end, children: [
Text('$_systolic', style: const TextStyle(fontSize: 56, fontWeight: FontWeight.w800, color: AppColors.textPrimary, height: 1)),
Padding(padding: const EdgeInsets.only(bottom: 10), child: Text('/', style: TextStyle(fontSize: 24, color: AppColors.textHint.withOpacity(0.5)))),
Text('$_diastolic', style: const TextStyle(fontSize: 56, fontWeight: FontWeight.w800, color: AppColors.textPrimary, height: 1)),
const SizedBox(width: 8),
Padding(padding: const EdgeInsets.only(bottom: 12), child: Text('mmHg', style: TextStyle(fontSize: 15, color: AppColors.textHint))),
]),
if (_pulse != null)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
decoration: BoxDecoration(color: const Color(0xFFEFF6FF), borderRadius: BorderRadius.circular(20)),
child: Text('脉搏 $_pulse bpm', style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w500, color: AppColors.primary)),
if (_readingReceived) ...[
Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'$_systolic',
style: const TextStyle(
fontSize: 56,
fontWeight: FontWeight.w800,
color: AppColors.textPrimary,
height: 1,
),
),
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Text(
'/',
style: TextStyle(
fontSize: 24,
color: AppColors.textHint.withValues(alpha: 0.5),
),
),
),
Text(
'$_diastolic',
style: const TextStyle(
fontSize: 56,
fontWeight: FontWeight.w800,
color: AppColors.textPrimary,
height: 1,
),
),
const SizedBox(width: 8),
Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Text(
'mmHg',
style: TextStyle(fontSize: 15, color: AppColors.textHint),
),
),
],
),
if (_pulse != null)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 14,
vertical: 6,
),
decoration: BoxDecoration(
color: AppColors.infoLight,
borderRadius: BorderRadius.circular(20),
),
child: Text(
'脉搏 $_pulse bpm',
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: AppColors.primary,
),
),
),
),
const SizedBox(height: 16),
const Text(
'数据已自动同步',
style: TextStyle(fontSize: 14, color: AppColors.textHint),
),
const SizedBox(height: 8),
const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
strokeWidth: 2,
color: AppColors.primary,
),
),
const SizedBox(height: 16),
const Text('数据已自动同步', style: TextStyle(fontSize: 14, color: AppColors.textHint)),
const SizedBox(height: 8),
const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2, color: AppColors.primary)),
] else ...[
const Text('请按下血压计的开始键进行测量', style: TextStyle(fontSize: 15, color: AppColors.textHint)),
const SizedBox(height: 32),
AnimatedBuilder(
animation: _pulseAnim,
builder: (_, __) => Container(
width: 48, height: 48,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: AppColors.primary.withOpacity(0.3), width: 2),
),
child: Center(
child: Transform.scale(
scale: _pulseAnim.value,
child: Container(width: 12, height: 12, decoration: const BoxDecoration(shape: BoxShape.circle, color: AppColors.primary)),
] else ...[
const Text(
'请按下血压计的开始键进行测量',
style: TextStyle(fontSize: 15, color: AppColors.textHint),
),
const SizedBox(height: 32),
AnimatedBuilder(
animation: _pulseAnim,
builder: (_, __) => Container(
width: 48,
height: 48,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: AppColors.primary.withValues(alpha: 0.3),
width: 2,
),
),
child: Center(
child: Transform.scale(
scale: _pulseAnim.value,
child: Container(
width: 12,
height: 12,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: AppColors.primary,
),
),
),
),
),
),
),
],
],
]),
),
),
);
@@ -308,32 +458,78 @@ class _DeviceScanPageState extends ConsumerState<DeviceScanPage>
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: const Color(0xFFEEEEEE)),
border: Border.all(color: AppColors.border),
boxShadow: AppColors.cardShadowLight,
),
child: Row(children: [
Container(
width: 44, height: 44,
decoration: BoxDecoration(color: const Color(0xFFF0F0FF), borderRadius: BorderRadius.circular(12)),
child: const Icon(Icons.bluetooth, size: 22, color: AppColors.primary),
),
const SizedBox(width: 12),
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(name, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: AppColors.textPrimary)),
const SizedBox(height: 2),
Text('${r.device.remoteId} · 信号: ${_rssiLabel(r.rssi)}', style: const TextStyle(fontSize: 12, color: AppColors.textHint)),
])),
if (isConnecting)
const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2))
else
GestureDetector(
onTap: () => _connect(r),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
decoration: BoxDecoration(color: AppColors.primary, borderRadius: BorderRadius.circular(12)),
child: const Text('连接', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Colors.white)),
child: Row(
children: [
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: AppColors.avatarBg,
borderRadius: BorderRadius.circular(12),
),
child: const Icon(
Icons.bluetooth,
size: 22,
color: AppColors.primary,
),
),
]),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.textPrimary,
),
),
const SizedBox(height: 2),
Text(
'${r.device.remoteId} · 信号: ${_rssiLabel(r.rssi)}',
style: const TextStyle(
fontSize: 12,
color: AppColors.textHint,
),
),
],
),
),
if (isConnecting)
const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 2),
)
else
GestureDetector(
onTap: () => _connect(r),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 10,
),
decoration: BoxDecoration(
color: AppColors.primary,
borderRadius: BorderRadius.circular(12),
),
child: const Text(
'连接',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
),
],
),
);
}