Commit d6fc2a2b authored by 张宏's avatar 张宏
parents d2db426e 2160220c
...@@ -376,6 +376,15 @@ class BleBluetoothManager<T> { ...@@ -376,6 +376,15 @@ class BleBluetoothManager<T> {
return; return;
} }
final hex = bytesToHex(data);
Log.warn(
'🔥🔥🔥 BLE_WRITE_DEBUG write_data '
'deviceId=${characteristic.deviceId} '
'service=${characteristic.serviceId} '
'characteristic=${characteristic.characteristicId} '
'withoutResponse=$withoutResponse '
'hex=$hex',
);
try { try {
if (withoutResponse) { if (withoutResponse) {
await _ble.writeCharacteristicWithoutResponse( await _ble.writeCharacteristicWithoutResponse(
...@@ -385,9 +394,11 @@ class BleBluetoothManager<T> { ...@@ -385,9 +394,11 @@ class BleBluetoothManager<T> {
} else { } else {
await _ble.writeCharacteristicWithResponse(characteristic, value: data); await _ble.writeCharacteristicWithResponse(characteristic, value: data);
} }
_notifyMessage('蓝牙数据发送成功: ${bytesToHex(data)}'); Log.warn('🔥🔥🔥 BLE_WRITE_DEBUG write_success hex=$hex');
_notifyMessage('蓝牙数据发送成功: $hex');
_sendResultController.add(true); _sendResultController.add(true);
} catch (error) { } catch (error) {
Log.warn('🔥🔥🔥 BLE_WRITE_DEBUG write_error hex=$hex error=$error');
_notifyMessage('蓝牙数据发送失败: $error'); _notifyMessage('蓝牙数据发送失败: $error');
_sendResultController.add(false); _sendResultController.add(false);
} }
......
This diff is collapsed.
...@@ -2,6 +2,9 @@ import 'package:auto_route/auto_route.dart'; ...@@ -2,6 +2,9 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_bloc.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_event.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_state.dart';
import 'package:laki_icu_app/models/bo/monitoring_bo.dart'; import 'package:laki_icu_app/models/bo/monitoring_bo.dart';
import 'cubit/device_control_index_cubit.dart'; import 'cubit/device_control_index_cubit.dart';
...@@ -130,23 +133,32 @@ class _DeviceControlLayout extends StatelessWidget { ...@@ -130,23 +133,32 @@ class _DeviceControlLayout extends StatelessWidget {
SizedBox(height: 24.h), SizedBox(height: 24.h),
Expanded( Expanded(
flex: 58, flex: 58,
child: Row( child: LayoutBuilder(
children: [ builder: (context, constraints) {
const Expanded( final gap = 24.w;
flex: 48, final metricCardWidth =
child: DeviceControlModePanel(), (constraints.maxWidth - gap * 3) / 4;
), final modePanelWidth = metricCardWidth * 2 + gap;
SizedBox(width: 24.w),
const Expanded( return Row(
flex: 23, children: [
child: DeviceControlWindPanel(), SizedBox(
), width: modePanelWidth,
SizedBox(width: 24.w), child: const DeviceControlModePanel(),
const Expanded( ),
flex: 29, SizedBox(width: gap),
child: DeviceControlTimePanel(), SizedBox(
), width: metricCardWidth,
], child: const DeviceControlWindPanel(),
),
SizedBox(width: gap),
SizedBox(
width: metricCardWidth,
child: const DeviceControlTimePanel(),
),
],
);
},
), ),
), ),
], ],
...@@ -169,14 +181,27 @@ class _DeviceControlLayout extends StatelessWidget { ...@@ -169,14 +181,27 @@ class _DeviceControlLayout extends StatelessWidget {
), ),
), ),
SizedBox(height: 24.h), SizedBox(height: 24.h),
const Expanded( Expanded(
flex: 20, flex: 20,
child: DeviceControlInfoPanel( child:
title: '开放供氧', BlocBuilder<DeviceControlBloc, DeviceControlState>(
actionText: 'Off', buildWhen: (previous, current) =>
icon: Icons.air, previous.data.openOxygen !=
body: '开启后风扇打开、制冷、加热和\n循环等设备暂停。', current.data.openOxygen,
warning: '*保持设备周围空气相对禁止,严禁烟火', builder: (context, state) {
final isOn = state.data.openOxygen.isOn;
return DeviceControlInfoPanel(
title: '开放供氧',
actionText: isOn ? 'ON' : 'Off',
active: isOn,
icon: Icons.air,
body: '开启后风扇打开、制冷、加热和\n循环等设备暂停。',
warning: '*保持设备周围空气相对禁止,严禁烟火',
onTap: () => context.read<DeviceControlBloc>().add(
DeviceControlOpenOxygenSwitchChanged(!isOn),
),
);
},
), ),
), ),
SizedBox(height: 24.h), SizedBox(height: 24.h),
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_bloc.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_event.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_state.dart';
import 'package:laki_icu_app/models/bo/device_control_bo.dart';
import 'device_control_common.dart'; import 'device_control_common.dart';
...@@ -9,43 +14,174 @@ class DeviceControlCarePanel extends StatelessWidget { ...@@ -9,43 +14,174 @@ class DeviceControlCarePanel extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DeviceControlPanelFrame( return BlocBuilder<DeviceControlBloc, DeviceControlState>(
backgroundAsset: assetPanelWide, buildWhen: (previous, current) =>
padding: EdgeInsets.fromLTRB(30.w, 26.h, 30.w, 24.h), previous.data.careLevel != current.data.careLevel,
child: Column( builder: (context, state) {
crossAxisAlignment: CrossAxisAlignment.start, final currentLevel = state.data.careLevel.currentLevel;
children: [
const DeviceControlPanelTitle('护理等级'), return DeviceControlPanelFrame(
const Spacer(), backgroundAsset: assetPanelWide,
Container( padding: EdgeInsets.fromLTRB(30.w, 26.h, 30.w, 24.h),
height: 20.h, child: Column(
decoration: BoxDecoration( crossAxisAlignment: CrossAxisAlignment.start,
borderRadius: BorderRadius.circular(10.r), children: [
gradient: const LinearGradient( const DeviceControlPanelTitle('护理等级'),
colors: [ const Spacer(),
Color(0xFFDCEFFC), _CareLevelBar(currentLevel: currentLevel),
Color(0xFF71FFCF), SizedBox(height: 24.h),
Color(0xFFE4CF1D), Row(
Color(0xFFFFA11B), children: [
Color(0xFFFF5945), for (final item in _careLevelItems)
Color(0xFFFFFFFF), Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => context.read<DeviceControlBloc>().add(
DeviceControlCareLevelChanged(item.level),
),
child: Text(
item.label,
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white,
fontSize: 24.sp,
),
),
),
),
], ],
), ),
), ],
), ),
SizedBox(height: 24.h), );
Row( },
mainAxisAlignment: MainAxisAlignment.spaceBetween, );
}
}
class _CareLevelBar extends StatelessWidget {
const _CareLevelBar({required this.currentLevel});
final CareLevel currentLevel;
@override
Widget build(BuildContext context) {
final activeIndex = _careLevelItems.indexWhere(
(item) => item.level == currentLevel,
);
return LayoutBuilder(
builder: (context, constraints) {
final segmentGap = 4.w;
final knobSize = 54.w;
final segmentWidth =
(constraints.maxWidth - segmentGap * (_careLevelItems.length - 1)) /
_careLevelItems.length;
final knobLeft = (segmentWidth + segmentGap) * activeIndex +
segmentWidth -
knobSize / 2;
return SizedBox(
height: knobSize,
child: Stack(
clipBehavior: Clip.none,
alignment: Alignment.centerLeft,
children: [ children: [
for (final item in const ['关闭', '三级', '二级', '一级', '特级']) Positioned(
Text( left: 0,
item, right: 0,
style: TextStyle(color: Colors.white, fontSize: 24.sp), top: (knobSize - 20.h) / 2,
child: Row(
children: [
for (var index = 0;
index < _careLevelItems.length;
index++) ...[
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () =>
context.read<DeviceControlBloc>().add(
DeviceControlCareLevelChanged(
_careLevelItems[index].level,
),
),
child: Container(
height: 20.h,
decoration: BoxDecoration(
color: index <= activeIndex
? _careLevelItems[index].color
: const Color(0xFF6A7481),
borderRadius: _segmentRadius(index),
boxShadow: index <= activeIndex
? [
BoxShadow(
color: _careLevelItems[index]
.color
.withValues(alpha: 0.35),
blurRadius: 8.r,
),
]
: null,
),
),
),
),
if (index < _careLevelItems.length - 1)
SizedBox(width: segmentGap),
],
],
),
),
Positioned(
left: knobLeft.clamp(0, constraints.maxWidth - knobSize),
child: Container(
width: knobSize,
height: knobSize,
decoration: BoxDecoration(
color: const Color(0xFFF7F7F7),
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.white.withValues(alpha: 0.72),
blurRadius: 10.r,
),
],
),
), ),
),
], ],
), ),
], );
), },
); );
} }
BorderRadius _segmentRadius(int index) {
final radius = Radius.circular(12.r);
if (index == 0) {
return BorderRadius.horizontal(left: radius);
}
if (index == _careLevelItems.length - 1) {
return BorderRadius.horizontal(right: radius);
}
return BorderRadius.zero;
}
}
const _careLevelItems = [
_CareLevelItem('关闭', CareLevel.off, Color(0xFFE5F7FF)),
_CareLevelItem('三级', CareLevel.level3, Color(0xFF60F2B6)),
_CareLevelItem('二级', CareLevel.level2, Color(0xFFFFCE1B)),
_CareLevelItem('一级', CareLevel.level1, Color(0xFFFF8D2E)),
_CareLevelItem('特级', CareLevel.special, Color(0xFFFF554C)),
];
class _CareLevelItem {
const _CareLevelItem(this.label, this.level, this.color);
final String label;
final CareLevel level;
final Color color;
} }
...@@ -12,6 +12,8 @@ class DeviceControlInfoPanel extends StatelessWidget { ...@@ -12,6 +12,8 @@ class DeviceControlInfoPanel extends StatelessWidget {
required this.icon, required this.icon,
required this.body, required this.body,
this.warning, this.warning,
this.active = false,
this.onTap,
}); });
final String title; final String title;
...@@ -19,49 +21,61 @@ class DeviceControlInfoPanel extends StatelessWidget { ...@@ -19,49 +21,61 @@ class DeviceControlInfoPanel extends StatelessWidget {
final IconData icon; final IconData icon;
final String body; final String body;
final String? warning; final String? warning;
final bool active;
final VoidCallback? onTap;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DeviceControlPanelFrame( return GestureDetector(
backgroundAsset: assetPanelWide, behavior: HitTestBehavior.opaque,
padding: EdgeInsets.fromLTRB(30.w, 22.h, 30.w, 24.h), onTap: onTap,
child: Column( child: DeviceControlPanelFrame(
crossAxisAlignment: CrossAxisAlignment.start, backgroundAsset: assetPanelWide,
children: [ padding: EdgeInsets.fromLTRB(30.w, 22.h, 30.w, 24.h),
Row( child: Column(
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Expanded(child: DeviceControlPanelTitle(title)), children: [
DeviceControlPill(text: actionText), Row(
], children: [
), Expanded(child: DeviceControlPanelTitle(title)),
const Spacer(), DeviceControlPill(text: actionText, active: active),
Row( ],
children: [ ),
Icon(icon, color: const Color(0xFF6AC6F2), size: 54.w), const Spacer(),
SizedBox(width: 28.w), Row(
Expanded( children: [
child: Text( Icon(
body, icon,
style: TextStyle( color: active
color: const Color(0xFFC9F8FF), ? const Color(0xFF45F36F)
fontSize: 20.sp, : const Color(0xFF6AC6F2),
height: 1.35, size: 54.w,
),
SizedBox(width: 28.w),
Expanded(
child: Text(
body,
style: TextStyle(
color: const Color(0xFFC9F8FF),
fontSize: 20.sp,
height: 1.35,
),
), ),
), ),
],
),
if (warning != null) ...[
SizedBox(height: 8.h),
Text(
warning!,
style: TextStyle(
color: const Color(0xFFFFC400),
fontSize: 16.sp,
),
), ),
], ],
),
if (warning != null) ...[
SizedBox(height: 8.h),
Text(
warning!,
style: TextStyle(
color: const Color(0xFFFFC400),
fontSize: 16.sp,
),
),
], ],
], ),
), ),
); );
} }
......
...@@ -5,6 +5,7 @@ import 'package:laki_icu_app/blocs/device_control/device_control_bloc.dart'; ...@@ -5,6 +5,7 @@ import 'package:laki_icu_app/blocs/device_control/device_control_bloc.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_event.dart'; import 'package:laki_icu_app/blocs/device_control/device_control_event.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_state.dart'; import 'package:laki_icu_app/blocs/device_control/device_control_state.dart';
import 'package:laki_icu_app/models/bo/monitoring_bo.dart'; import 'package:laki_icu_app/models/bo/monitoring_bo.dart';
import 'package:laki_icu_app/utils/numeric_keyboard.dart';
import 'device_control_common.dart'; import 'device_control_common.dart';
...@@ -64,6 +65,12 @@ class DeviceControlMetricCard extends StatelessWidget { ...@@ -64,6 +65,12 @@ class DeviceControlMetricCard extends StatelessWidget {
isOxygen: isOxygen, isOxygen: isOxygen,
isCo2: isCo2, isCo2: isCo2,
); );
final setValueEventBuilder = _setValueEventBuilder(
isTemperature: isTemperature,
isHumidity: isHumidity,
isOxygen: isOxygen,
isCo2: isCo2,
);
return DeviceControlPanelFrame( return DeviceControlPanelFrame(
active: isOxygen, active: isOxygen,
...@@ -147,15 +154,30 @@ class DeviceControlMetricCard extends StatelessWidget { ...@@ -147,15 +154,30 @@ class DeviceControlMetricCard extends StatelessWidget {
), ),
), ),
const Spacer(), const Spacer(),
Text( GestureDetector(
setValue, behavior: HitTestBehavior.opaque,
style: TextStyle( onTap: setValueEventBuilder == null
color: isCo2 ? null
? const Color(0xFFFFC400) : () => _showSetValueKeyboard(
: const Color(0xFF00B7F4), context,
fontSize: 64.sp, initialValue: setValue,
height: 1, decimalEnabled: isTemperature,
fontWeight: FontWeight.bold, eventBuilder: setValueEventBuilder,
),
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 18.w, vertical: 8.h),
child: Text(
setValue,
style: TextStyle(
color: isCo2
? const Color(0xFFFFC400)
: const Color(0xFF00B7F4),
fontSize: 64.sp,
height: 1,
fontWeight: FontWeight.bold,
),
),
), ),
), ),
const Spacer(), const Spacer(),
...@@ -206,6 +228,46 @@ class DeviceControlMetricCard extends StatelessWidget { ...@@ -206,6 +228,46 @@ class DeviceControlMetricCard extends StatelessWidget {
} }
return null; return null;
} }
static DeviceControlEvent Function(String value)? _setValueEventBuilder({
required bool isTemperature,
required bool isHumidity,
required bool isOxygen,
required bool isCo2,
}) {
if (isTemperature) {
return (value) => DeviceControlCabinTempSetValueChanged(value);
}
if (isHumidity) {
return (value) => DeviceControlCabinHumiditySetValueChanged(value);
}
if (isOxygen) {
return (value) => DeviceControlOxygenConcentrationSetValueChanged(value);
}
if (isCo2) {
return (value) =>
DeviceControlCO2ConcentrationAlarmThresholdChanged(value);
}
return null;
}
static Future<void> _showSetValueKeyboard(
BuildContext context, {
required String initialValue,
required bool decimalEnabled,
required DeviceControlEvent Function(String value) eventBuilder,
}) async {
final result = await NumericKeyboard.show(
context,
initialValue: initialValue == '--' ? '' : initialValue,
decimalEnabled: decimalEnabled,
);
if (!context.mounted || result == null) return;
final value = result.trim();
if (value.isEmpty || value == '.') return;
context.read<DeviceControlBloc>().add(eventBuilder(value));
}
} }
class _MetricAdjustButton extends StatelessWidget { class _MetricAdjustButton extends StatelessWidget {
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_bloc.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_event.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_state.dart';
import 'package:laki_icu_app/models/bo/device_control_bo.dart';
import 'device_control_common.dart'; import 'device_control_common.dart';
...@@ -9,33 +14,97 @@ class DeviceControlModePanel extends StatelessWidget { ...@@ -9,33 +14,97 @@ class DeviceControlModePanel extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const items = [ return BlocBuilder<DeviceControlBloc, DeviceControlState>(
_ModeItem(label: '外循环', icon: Icons.sync, active: true), buildWhen: (previous, current) =>
_ModeItem(label: '检查灯', icon: Icons.light), previous.data.circulationMode != current.data.circulationMode ||
_ModeItem(label: '照明灯', icon: Icons.lightbulb), previous.data.lightControl != current.data.lightControl,
_ModeItem(label: '内循环', icon: Icons.autorenew), builder: (context, state) {
_ModeItem(label: '蓝光', icon: Icons.wb_sunny_outlined), final circulationMode = state.data.circulationMode.currentMode;
_ModeItem(label: '红光', icon: Icons.wb_sunny), final lightControl = state.data.lightControl;
]; final items = [
_ModeItem(
return DeviceControlPanelFrame( label: '外循环',
backgroundAsset: assetPanelLarge, icon: Icons.sync,
padding: EdgeInsets.all(28.w), active: circulationMode == CirculationMode.external,
child: GridView.count( event: const DeviceControlCirculationModeChanged(
crossAxisCount: 3, CirculationMode.external,
crossAxisSpacing: 24.w,
mainAxisSpacing: 24.h,
physics: const NeverScrollableScrollPhysics(),
childAspectRatio: 1.1,
children: [
for (final item in items)
_ModeButton(
label: item.label,
icon: item.icon,
active: item.active,
), ),
], ),
), _ModeItem(
label: '检查灯',
icon: Icons.light,
active: lightControl.checkLightOn,
event: DeviceControlCheckLightSwitchChanged(
!lightControl.checkLightOn,
),
),
_ModeItem(
label: '照明灯',
icon: Icons.lightbulb,
active: lightControl.illuminationOn,
event: DeviceControlIlluminationLightSwitchChanged(
!lightControl.illuminationOn,
),
),
_ModeItem(
label: '内循环',
icon: Icons.autorenew,
active: circulationMode == CirculationMode.internal,
event: const DeviceControlCirculationModeChanged(
CirculationMode.internal,
),
),
_ModeItem(
label: '蓝光',
icon: Icons.wb_sunny_outlined,
active: lightControl.blueLightOn,
event: DeviceControlBlueLightSwitchChanged(
!lightControl.blueLightOn,
),
),
_ModeItem(
label: '红光',
icon: Icons.wb_sunny,
active: lightControl.redLightOn,
event: DeviceControlRedLightSwitchChanged(
!lightControl.redLightOn,
),
),
];
return DeviceControlPanelFrame(
backgroundAsset: assetPanelLarge,
padding: EdgeInsets.fromLTRB(30.w, 30.h, 30.w, 30.h),
child: LayoutBuilder(
builder: (context, constraints) {
final horizontalGap = 22.w;
final verticalGap = 22.h;
final itemWidth = (constraints.maxWidth - horizontalGap * 2) / 3;
final itemHeight = (constraints.maxHeight - verticalGap) / 2;
return Wrap(
spacing: horizontalGap,
runSpacing: verticalGap,
children: [
for (final item in items)
SizedBox(
width: itemWidth,
height: itemHeight,
child: _ModeButton(
label: item.label,
icon: item.icon,
active: item.active,
onTap: () => context.read<DeviceControlBloc>().add(
item.event,
),
),
),
],
);
},
),
);
},
); );
} }
} }
...@@ -45,37 +114,51 @@ class _ModeButton extends StatelessWidget { ...@@ -45,37 +114,51 @@ class _ModeButton extends StatelessWidget {
required this.label, required this.label,
required this.icon, required this.icon,
this.active = false, this.active = false,
this.onTap,
}); });
final String label; final String label;
final IconData icon; final IconData icon;
final bool active; final bool active;
final VoidCallback? onTap;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final color = active ? const Color(0xFF45F36F) : const Color(0xFF7DC4EA); final color = active ? const Color(0xFF45F36F) : const Color(0xFF7DC4EA);
return Container( return GestureDetector(
decoration: deviceControlButtonDecoration( behavior: HitTestBehavior.opaque,
active: active, onTap: onTap,
backgroundAsset: assetArrowButton, child: Container(
), decoration: deviceControlButtonDecoration(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 18.h), active: active,
child: Column( backgroundAsset: assetArrowButton,
mainAxisAlignment: MainAxisAlignment.center, ),
children: [ padding: EdgeInsets.fromLTRB(12.w, 6.h, 12.w, 16.h),
Icon(icon, color: color, size: 56.w), child: Stack(
SizedBox(height: 20.h), alignment: Alignment.center,
Text( children: [
label, Positioned(
maxLines: 1, top: 28.h,
overflow: TextOverflow.ellipsis, child: Icon(icon, color: color, size: 100.w),
style: TextStyle(
color: color,
fontSize: 26.sp,
fontWeight: FontWeight.w700,
), ),
), Positioned(
], left: 0,
right: 0,
bottom: 0,
child: Text(
label,
maxLines: 1,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: color,
fontSize: 26.sp,
fontWeight: FontWeight.w700,
),
),
),
],
),
), ),
); );
} }
...@@ -85,10 +168,12 @@ class _ModeItem { ...@@ -85,10 +168,12 @@ class _ModeItem {
final String label; final String label;
final IconData icon; final IconData icon;
final bool active; final bool active;
final DeviceControlEvent event;
const _ModeItem({ const _ModeItem({
required this.label, required this.label,
required this.icon, required this.icon,
required this.event,
this.active = false, this.active = false,
}); });
} }
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_bloc.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_event.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_state.dart';
import 'package:laki_icu_app/utils/numeric_keyboard.dart';
import 'device_control_common.dart'; import 'device_control_common.dart';
...@@ -9,28 +14,97 @@ class DeviceControlTimePanel extends StatelessWidget { ...@@ -9,28 +14,97 @@ class DeviceControlTimePanel extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DeviceControlPanelFrame( return BlocBuilder<DeviceControlBloc, DeviceControlState>(
backgroundAsset: assetPanelTall, buildWhen: (previous, current) =>
padding: EdgeInsets.fromLTRB(34.w, 28.h, 34.w, 28.h), previous.data.nebulizationTime != current.data.nebulizationTime ||
child: Column( previous.data.disinfectionTime != current.data.disinfectionTime,
crossAxisAlignment: CrossAxisAlignment.start, builder: (context, state) {
children: [ final nebulizationMinutes = state.data.nebulizationTime.setMinutes;
const DeviceControlPanelTitle('设置雾化时间'), final disinfectionMinutes = state.data.disinfectionTime.setMinutes;
SizedBox(height: 18.h),
const Expanded( return DeviceControlPanelFrame(
child: DeviceControlDigitalValueBox(value: '00', unit: '分钟'), backgroundAsset: assetPanelTall,
), padding: EdgeInsets.fromLTRB(34.w, 28.h, 34.w, 28.h),
Divider(color: Colors.white.withValues(alpha: 0.16), height: 36.h), child: Column(
const DeviceControlPanelTitle('设置消毒时间'), crossAxisAlignment: CrossAxisAlignment.start,
SizedBox(height: 18.h), children: [
const Expanded( const DeviceControlPanelTitle('设置雾化时间'),
child: DeviceControlDigitalValueBox( SizedBox(height: 18.h),
value: '14', Expanded(
unit: '分钟', child: _TimeValueButton(
active: true, value: nebulizationMinutes,
), active: false,
onTap: () => _showTimeKeyboard(
context,
initialValue: nebulizationMinutes,
eventBuilder: (value) =>
DeviceControlNebulizationTimeChanged(value),
),
),
),
Divider(
color: Colors.white.withValues(alpha: 0.16),
height: 36.h,
),
const DeviceControlPanelTitle('设置消毒时间'),
SizedBox(height: 18.h),
Expanded(
child: _TimeValueButton(
value: disinfectionMinutes,
active: true,
onTap: () => _showTimeKeyboard(
context,
initialValue: disinfectionMinutes,
eventBuilder: (value) =>
DeviceControlDisinfectionTimeChanged(value),
),
),
),
],
), ),
], );
},
);
}
static Future<void> _showTimeKeyboard(
BuildContext context, {
required String initialValue,
required DeviceControlEvent Function(String value) eventBuilder,
}) async {
final result = await NumericKeyboard.show(
context,
initialValue: initialValue == '--' ? '' : initialValue,
decimalEnabled: false,
);
if (!context.mounted || result == null) return;
final value = result.trim();
if (value.isEmpty) return;
context.read<DeviceControlBloc>().add(eventBuilder(value));
}
}
class _TimeValueButton extends StatelessWidget {
const _TimeValueButton({
required this.value,
required this.active,
required this.onTap,
});
final String value;
final bool active;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: DeviceControlDigitalValueBox(
value: value,
unit: '分钟',
active: active,
), ),
); );
} }
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_bloc.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_event.dart';
import 'package:laki_icu_app/blocs/device_control/device_control_state.dart';
import 'package:laki_icu_app/models/bo/device_control_bo.dart';
import 'device_control_common.dart'; import 'device_control_common.dart';
...@@ -9,33 +14,62 @@ class DeviceControlWindPanel extends StatelessWidget { ...@@ -9,33 +14,62 @@ class DeviceControlWindPanel extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DeviceControlPanelFrame( return BlocBuilder<DeviceControlBloc, DeviceControlState>(
backgroundAsset: assetPanelTall, buildWhen: (previous, current) =>
padding: EdgeInsets.fromLTRB(34.w, 28.h, 34.w, 28.h), previous.data.windSpeed != current.data.windSpeed,
child: Column( builder: (context, state) {
crossAxisAlignment: CrossAxisAlignment.start, final currentMode = state.data.windSpeed.currentMode;
children: [
const DeviceControlPanelTitle('风速调节'), return DeviceControlPanelFrame(
SizedBox(height: 24.h), backgroundAsset: assetPanelTall,
const Expanded( padding: EdgeInsets.fromLTRB(34.w, 28.h, 34.w, 28.h),
child: _WideModeButton( child: Column(
label: '睡眠模式', crossAxisAlignment: CrossAxisAlignment.start,
icon: Icons.nightlight_round, children: [
), const DeviceControlPanelTitle('风速调节'),
), SizedBox(height: 24.h),
SizedBox(height: 18.h), Expanded(
const Expanded( child: _WideModeButton(
child: _WideModeButton( label: '睡眠模式',
label: '舒适模式', icon: Icons.nightlight_round,
icon: Icons.favorite_border, active: currentMode == WindSpeedMode.sleep,
), onTap: () => context.read<DeviceControlBloc>().add(
), const DeviceControlWindSpeedModeChanged(
SizedBox(height: 18.h), WindSpeedMode.sleep,
const Expanded( ),
child: _WideModeButton(label: '强劲模式', icon: Icons.air), ),
),
),
SizedBox(height: 18.h),
Expanded(
child: _WideModeButton(
label: '舒适模式',
icon: Icons.favorite_border,
active: currentMode == WindSpeedMode.comfort,
onTap: () => context.read<DeviceControlBloc>().add(
const DeviceControlWindSpeedModeChanged(
WindSpeedMode.comfort,
),
),
),
),
SizedBox(height: 18.h),
Expanded(
child: _WideModeButton(
label: '强劲模式',
icon: Icons.air,
active: currentMode == WindSpeedMode.strong,
onTap: () => context.read<DeviceControlBloc>().add(
const DeviceControlWindSpeedModeChanged(
WindSpeedMode.strong,
),
),
),
),
],
), ),
], );
), },
); );
} }
} }
...@@ -44,34 +78,46 @@ class _WideModeButton extends StatelessWidget { ...@@ -44,34 +78,46 @@ class _WideModeButton extends StatelessWidget {
const _WideModeButton({ const _WideModeButton({
required this.label, required this.label,
required this.icon, required this.icon,
this.active = false,
this.onTap,
}); });
final String label; final String label;
final IconData icon; final IconData icon;
final bool active;
final VoidCallback? onTap;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( final color = active ? const Color(0xFF45F36F) : const Color(0xFF7DC4EA);
width: double.infinity, return GestureDetector(
decoration: deviceControlButtonDecoration(backgroundAsset: assetButton), behavior: HitTestBehavior.opaque,
padding: EdgeInsets.symmetric(horizontal: 28.w), onTap: onTap,
child: Row( child: Container(
children: [ width: double.infinity,
Icon(icon, color: const Color(0xFF7DC4EA), size: 52.w), decoration: deviceControlButtonDecoration(
SizedBox(width: 34.w), active: active,
Expanded( backgroundAsset: assetButton,
child: Text( ),
label, padding: EdgeInsets.symmetric(horizontal: 28.w),
maxLines: 1, child: Row(
overflow: TextOverflow.ellipsis, children: [
style: TextStyle( Icon(icon, color: color, size: 52.w),
color: Colors.white, SizedBox(width: 34.w),
fontSize: 26.sp, Expanded(
fontWeight: FontWeight.w600, child: Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: color,
fontSize: 26.sp,
fontWeight: FontWeight.w600,
),
), ),
), ),
), ],
], ),
), ),
); );
} }
......
...@@ -36,6 +36,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -36,6 +36,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
StreamSubscription<BluetoothConnectionStatus>? _bluetoothStateSub; StreamSubscription<BluetoothConnectionStatus>? _bluetoothStateSub;
StreamSubscription<String>? _bluetoothMessageSub; StreamSubscription<String>? _bluetoothMessageSub;
StreamSubscription<BluetoothDataPacket>? _bluetoothDataSub; StreamSubscription<BluetoothDataPacket>? _bluetoothDataSub;
StreamSubscription<BluetoothReadInfoChangedEvent>? _bluetoothReadInfoSub;
StreamSubscription<McuReportChangedEvent>? _mcuReportChangedSub; StreamSubscription<McuReportChangedEvent>? _mcuReportChangedSub;
StreamSubscription<LakiMqttConnectionState>? _mqttStateSub; StreamSubscription<LakiMqttConnectionState>? _mqttStateSub;
StreamSubscription<LakiMqttMessage>? _mqttMessageSub; StreamSubscription<LakiMqttMessage>? _mqttMessageSub;
...@@ -69,6 +70,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -69,6 +70,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
_listenWebrtcState(); _listenWebrtcState();
_listenP2pState(); _listenP2pState();
_listenBluetoothState(); _listenBluetoothState();
_listenBluetoothReadInfo();
_listenMcuReportChanged(); _listenMcuReportChanged();
_loadBoundBluetoothDevice(); _loadBoundBluetoothDevice();
loadData(); loadData();
...@@ -178,13 +180,40 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -178,13 +180,40 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
void _listenMcuReportChanged() { void _listenMcuReportChanged() {
_mcuReportChangedSub = eventBus.on<McuReportChangedEvent>().listen((event) { _mcuReportChangedSub = eventBus.on<McuReportChangedEvent>().listen((event) {
if (isClosed) return; if (isClosed) return;
final metrics = _metricsFromBluetoothReport(event.report);
Log.warn(
'🔥🔥🔥 BLE_READ_DEBUG index_metrics_from_report '
'${_metricsLogText(metrics)}',
);
emit(state.copyWith( emit(state.copyWith(
latestMcuReport: event.report, latestMcuReport: event.report,
metrics: _metricsFromBluetoothReport(event.report), metrics: metrics,
)); ));
}); });
} }
void _listenBluetoothReadInfo() {
_bluetoothReadInfoSub =
eventBus.on<BluetoothReadInfoChangedEvent>().listen((event) {
if (isClosed) return;
final metrics = _metricsFromBluetoothReadInfo(event.info);
if (metrics == null) {
Log.warn(
'🔥🔥🔥 BLE_READ_DEBUG index_read_info_no_metrics '
'sn=${event.info.sn} temp=${event.info.mainTemperature} '
'humidity=${event.info.humidity} o2=${event.info.oxygenConcentration} '
'co2=${event.info.co2Measurement}',
);
return;
}
Log.warn(
'🔥🔥🔥 BLE_READ_DEBUG index_metrics_from_read_info '
'${_metricsLogText(metrics)}',
);
emit(state.copyWith(metrics: metrics));
});
}
String _appendBluetoothSideToSn(String sn) { String _appendBluetoothSideToSn(String sn) {
final cleanSn = sn.trim(); final cleanSn = sn.trim();
if (cleanSn.isEmpty) return ''; if (cleanSn.isEmpty) return '';
...@@ -241,8 +270,8 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -241,8 +270,8 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
)); ));
try { try {
final metrics = await _monitoringService.getMetrics(); // final metrics = await _monitoringService.getMetrics();
if (isClosed) return; // if (isClosed) return;
final patientInfo = await _monitoringService.getPatientInfo(); final patientInfo = await _monitoringService.getPatientInfo();
if (isClosed) return; if (isClosed) return;
final alerts = await _monitoringService.getAlerts(); final alerts = await _monitoringService.getAlerts();
...@@ -251,7 +280,6 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -251,7 +280,6 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
emit(state.copyWith( emit(state.copyWith(
status: MonitoringIndexStatus.success, status: MonitoringIndexStatus.success,
isLoading: false, isLoading: false,
metrics: metrics,
patientInfo: patientInfo, patientInfo: patientInfo,
alerts: alerts, alerts: alerts,
error: null, error: null,
...@@ -430,8 +458,8 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -430,8 +458,8 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
Future<void> refreshData() async { Future<void> refreshData() async {
try { try {
final metrics = await _monitoringService.getMetrics(); // final metrics = await _monitoringService.getMetrics();
if (isClosed) return; // if (isClosed) return;
final patientInfo = await _monitoringService.getPatientInfo(); final patientInfo = await _monitoringService.getPatientInfo();
if (isClosed) return; if (isClosed) return;
final alerts = await _monitoringService.getAlerts(); final alerts = await _monitoringService.getAlerts();
...@@ -439,7 +467,6 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -439,7 +467,6 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
emit(state.copyWith( emit(state.copyWith(
status: MonitoringIndexStatus.success, status: MonitoringIndexStatus.success,
metrics: metrics,
patientInfo: patientInfo, patientInfo: patientInfo,
alerts: alerts, alerts: alerts,
error: null, error: null,
...@@ -750,36 +777,98 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -750,36 +777,98 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
_mqttClient = null; _mqttClient = null;
} }
List<MonitoringMetricBO> _metricsFromBluetoothReport(McuReport report) { List<MonitoringMetricBO> _metricsFromBluetoothReport(
McuReport report, {
List<MonitoringMetricBO>? baseMetrics,
}) {
final metrics = baseMetrics ?? state.metrics;
final replacements = <String, MonitoringMetricBO>{
'舱内温度': _replaceMetricValue(
'舱内温度',
_formatReportTemperatureOrKeep(report.mainTemperature, '舱内温度'),
fallbackUnit: '℃',
baseMetrics: metrics,
),
'舱内湿度': _replaceMetricValue(
'舱内湿度',
_formatReportIntOrKeep(report.humidity, '舱内湿度'),
fallbackUnit: 'RH',
baseMetrics: metrics,
),
'氧气浓度': _replaceMetricValue(
'氧气浓度',
_formatReportIntOrKeep(report.oxygenConcentration, '氧气浓度'),
fallbackUnit: '%',
baseMetrics: metrics,
),
'二氧化碳': _replaceMetricValue(
'二氧化碳',
_formatReportIntOrKeep(report.co2Measurement, '二氧化碳'),
fallbackUnit: 'ppm',
baseMetrics: metrics,
),
};
if (metrics.isEmpty) {
return replacements.values.toList();
}
return [
for (final metric in metrics) replacements[metric.label] ?? metric,
];
}
List<MonitoringMetricBO>? _metricsFromBluetoothReadInfo(
BluetoothReadModel info,
) {
final hasMetric = info.mainTemperature != null ||
info.humidity != null ||
info.oxygenConcentration != null ||
info.co2Measurement != null;
if (!hasMetric) return null;
final metrics = state.metrics;
final replacements = <String, MonitoringMetricBO>{ final replacements = <String, MonitoringMetricBO>{
'舱内温度': _replaceMetricValue( '舱内温度': _replaceMetricValue(
'舱内温度', '舱内温度',
_formatReportTemperature(report.mainTemperature), info.mainTemperature == null
? _existingMetricValue('舱内温度') ?? '--'
: _formatReportTemperature(info.mainTemperature!),
fallbackUnit: '℃', fallbackUnit: '℃',
baseMetrics: metrics,
), ),
'舱内湿度': _replaceMetricValue( '舱内湿度': _replaceMetricValue(
'舱内湿度', '舱内湿度',
_formatReportInt(report.humidity), info.humidity == null
? _existingMetricValue('舱内湿度') ?? '--'
: '${info.humidity}',
fallbackUnit: 'RH', fallbackUnit: 'RH',
baseMetrics: metrics,
), ),
'氧气浓度': _replaceMetricValue( '氧气浓度': _replaceMetricValue(
'氧气浓度', '氧气浓度',
_formatReportInt(report.oxygenConcentration), info.oxygenConcentration == null
? _existingMetricValue('氧气浓度') ?? '--'
: '${info.oxygenConcentration}',
fallbackUnit: '%', fallbackUnit: '%',
baseMetrics: metrics,
), ),
'二氧化碳': _replaceMetricValue( '二氧化碳': _replaceMetricValue(
'二氧化碳', '二氧化碳',
_formatReportInt(report.co2Measurement), info.co2Measurement == null
? _existingMetricValue('二氧化碳') ?? '--'
: '${info.co2Measurement}',
fallbackUnit: 'ppm', fallbackUnit: 'ppm',
baseMetrics: metrics,
), ),
}; };
if (state.metrics.isEmpty) { if (metrics.isEmpty) {
return replacements.values.toList(); return replacements.values.toList();
} }
return [ return [
for (final metric in state.metrics) replacements[metric.label] ?? metric, for (final metric in metrics) replacements[metric.label] ?? metric,
]; ];
} }
...@@ -787,9 +876,11 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -787,9 +876,11 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
String label, String label,
String value, { String value, {
required String fallbackUnit, required String fallbackUnit,
List<MonitoringMetricBO>? baseMetrics,
}) { }) {
final metrics = baseMetrics ?? state.metrics;
MonitoringMetricBO? existing; MonitoringMetricBO? existing;
for (final metric in state.metrics) { for (final metric in metrics) {
if (metric.label == label) { if (metric.label == label) {
existing = metric; existing = metric;
break; break;
...@@ -817,8 +908,29 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -817,8 +908,29 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
return fixed.endsWith('.0') ? fixed.substring(0, fixed.length - 2) : fixed; return fixed.endsWith('.0') ? fixed.substring(0, fixed.length - 2) : fixed;
} }
String _formatReportInt(int value) { String _formatReportTemperatureOrKeep(double value, String label) {
return value < 0 ? '--' : '$value'; if (!value.isNaN) return _formatReportTemperature(value);
return _existingMetricValue(label) ?? '--';
}
String _formatReportIntOrKeep(int value, String label) {
if (value >= 0) return '$value';
return _existingMetricValue(label) ?? '--';
}
String? _existingMetricValue(String label) {
for (final metric in state.metrics) {
if (metric.label == label && metric.value != '--') {
return metric.value;
}
}
return null;
}
String _metricsLogText(List<MonitoringMetricBO> metrics) {
return metrics
.map((item) => '${item.label}=${item.value}${item.unit}')
.join(' ');
} }
/// 清空宠物信息(出舱) /// 清空宠物信息(出舱)
...@@ -907,6 +1019,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -907,6 +1019,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
_bluetoothStateSub?.cancel(); _bluetoothStateSub?.cancel();
_bluetoothMessageSub?.cancel(); _bluetoothMessageSub?.cancel();
_bluetoothDataSub?.cancel(); _bluetoothDataSub?.cancel();
_bluetoothReadInfoSub?.cancel();
_mcuReportChangedSub?.cancel(); _mcuReportChangedSub?.cancel();
_webrtcService.dispose(); _webrtcService.dispose();
_p2pVideoService.dispose(); _p2pVideoService.dispose();
......
...@@ -120,7 +120,7 @@ class _MonitoringIndexContentState extends State<MonitoringIndexContent> { ...@@ -120,7 +120,7 @@ class _MonitoringIndexContentState extends State<MonitoringIndexContent> {
children: [ children: [
Expanded( Expanded(
flex: 32, flex: 32,
child: state.metrics.isEmpty ? _buildMetricsEmpty() : _buildMetrics(state.metrics), child: _buildMetrics(state.metrics),
), ),
SizedBox(height: 24.h), SizedBox(height: 24.h),
Expanded( Expanded(
...@@ -157,6 +157,7 @@ class _MonitoringIndexContentState extends State<MonitoringIndexContent> { ...@@ -157,6 +157,7 @@ class _MonitoringIndexContentState extends State<MonitoringIndexContent> {
); );
} }
// ignore: unused_element
Widget _buildMetricsEmpty() { Widget _buildMetricsEmpty() {
return Container( return Container(
width: double.infinity, width: double.infinity,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment