Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
laki_icu_app
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张宏
laki_icu_app
Commits
bccdf520
Commit
bccdf520
authored
Jun 24, 2026
by
张宏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
11111
parent
e779c58a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
2217 additions
and
2 deletions
+2217
-2
device_control_bloc.dart
lib/blocs/device_control/device_control_bloc.dart
+713
-0
device_control_event.dart
lib/blocs/device_control/device_control_event.dart
+349
-0
device_control_state.dart
lib/blocs/device_control/device_control_state.dart
+123
-0
main.dart
lib/main.dart
+18
-2
device_control_bo.dart
lib/models/bo/device_control_bo.dart
+1013
-0
pubspec.yaml
pubspec.yaml
+1
-0
No files found.
lib/blocs/device_control/device_control_bloc.dart
0 → 100644
View file @
bccdf520
import
'package:hydrated_bloc/hydrated_bloc.dart'
;
import
'device_control_event.dart'
;
import
'device_control_state.dart'
;
import
'package:laki_icu_app/models/bo/device_control_bo.dart'
;
/// 用途:设备控制Bloc
/// 涉及页面:设备控制页面
/// 说明:提供各个子模块的获取和设置方法,方便MCU单元调用
/// 使用 HydratedBloc 持久化用户设置,MCU获取的值不做持久化
class
DeviceControlBloc
extends
HydratedBloc
<
DeviceControlEvent
,
DeviceControlState
>
{
DeviceControlBloc
()
:
super
(
const
DeviceControlState
())
{
// ==================== 基础事件 ====================
on
<
DeviceControlLoadRequested
>(
_onLoadRequested
);
on
<
DeviceControlDataUpdated
>(
_onDataUpdated
);
// ==================== 设备SN事件 ====================
on
<
DeviceControlSnFetched
>(
_onSnFetched
);
on
<
DeviceControlSnChanged
>(
_onSnChanged
);
// ==================== 舱内温度控制事件 ====================
on
<
DeviceControlCabinTempCurrentValueFetched
>(
_onCabinTempCurrentValueFetched
);
on
<
DeviceControlCabinTempSetValueChanged
>(
_onCabinTempSetValueChanged
);
on
<
DeviceControlCabinTempSwitchChanged
>(
_onCabinTempSwitchChanged
);
// ==================== 舱内湿度控制事件 ====================
on
<
DeviceControlCabinHumidityCurrentValueFetched
>(
_onCabinHumidityCurrentValueFetched
);
on
<
DeviceControlCabinHumiditySetValueChanged
>(
_onCabinHumiditySetValueChanged
);
on
<
DeviceControlCabinHumiditySwitchChanged
>(
_onCabinHumiditySwitchChanged
);
// ==================== 氧气浓度控制事件 ====================
on
<
DeviceControlOxygenConcentrationCurrentValueFetched
>(
_onOxygenConcentrationCurrentValueFetched
);
on
<
DeviceControlOxygenConcentrationSetValueChanged
>(
_onOxygenConcentrationSetValueChanged
);
on
<
DeviceControlOxygenConcentrationSwitchChanged
>(
_onOxygenConcentrationSwitchChanged
);
// ==================== 二氧化碳浓度控制事件 ====================
on
<
DeviceControlCO2ConcentrationCurrentValueFetched
>(
_onCO2ConcentrationCurrentValueFetched
);
on
<
DeviceControlCO2ConcentrationAlarmThresholdChanged
>(
_onCO2ConcentrationAlarmThresholdChanged
);
// ==================== 护理等级控制事件 ====================
on
<
DeviceControlCareLevelChanged
>(
_onCareLevelChanged
);
// ==================== 新风进化控制事件 ====================
on
<
DeviceControlFreshAirModeChanged
>(
_onFreshAirModeChanged
);
// ==================== 风速调节控制事件 ====================
on
<
DeviceControlWindSpeedModeChanged
>(
_onWindSpeedModeChanged
);
// ==================== 雾化时间设置事件 ====================
on
<
DeviceControlNebulizationTimeChanged
>(
_onNebulizationTimeChanged
);
// ==================== 消毒时间设置事件 ====================
on
<
DeviceControlDisinfectionTimeChanged
>(
_onDisinfectionTimeChanged
);
// ==================== 开放供氧控制事件 ====================
on
<
DeviceControlOpenOxygenSwitchChanged
>(
_onOpenOxygenSwitchChanged
);
// ==================== 供氧计时事件 ====================
on
<
DeviceControlOxygenTimerUpdated
>(
_onOxygenTimerUpdated
);
on
<
DeviceControlOxygenTimerCleared
>(
_onOxygenTimerCleared
);
// ==================== 循环模式控制事件 ====================
on
<
DeviceControlCirculationModeChanged
>(
_onCirculationModeChanged
);
// ==================== 灯光控制事件 ====================
on
<
DeviceControlCheckLightSwitchChanged
>(
_onCheckLightSwitchChanged
);
on
<
DeviceControlIlluminationLightSwitchChanged
>(
_onIlluminationLightSwitchChanged
);
on
<
DeviceControlBlueLightSwitchChanged
>(
_onBlueLightSwitchChanged
);
on
<
DeviceControlRedLightSwitchChanged
>(
_onRedLightSwitchChanged
);
// ==================== 全局统计数据事件 ====================
on
<
DeviceControlTotalRunTimeUpdated
>(
_onTotalRunTimeUpdated
);
on
<
DeviceControlEnvironmentTempUpdated
>(
_onEnvironmentTempUpdated
);
on
<
DeviceControlTotalOxygenTimeUpdated
>(
_onTotalOxygenTimeUpdated
);
on
<
DeviceControlResetSettings
>(
_onResetSettings
);
// 加载初始化数据
add
(
const
DeviceControlLoadRequested
());
}
// ==================== HydratedBloc 持久化 ====================
@override
DeviceControlState
?
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
DeviceControlState
.
fromJson
(
json
);
}
@override
Map
<
String
,
dynamic
>?
toJson
(
DeviceControlState
state
)
{
return
state
.
toJson
();
}
// ==================== 基础事件处理 ====================
Future
<
void
>
_onLoadRequested
(
DeviceControlLoadRequested
event
,
Emitter
<
DeviceControlState
>
emit
,
)
async
{
emit
(
state
.
copyWith
(
isLoading:
true
,
clearError:
true
));
try
{
// 从存储中加载设备控制数据
// TODO: 实现从存储加载逻辑
emit
(
state
.
copyWith
(
isLoading:
false
,
clearError:
true
));
}
catch
(
e
)
{
emit
(
state
.
copyWith
(
isLoading:
false
,
error:
e
.
toString
()));
}
}
void
_onDataUpdated
(
DeviceControlDataUpdated
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
emit
(
state
.
copyWith
(
data:
event
.
data
,
clearError:
true
));
}
// ==================== 设备SN事件处理 ====================
/// [MCU调用] 更新设备SN(从MCU获取的真实数据)
void
_onSnFetched
(
DeviceControlSnFetched
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
sn:
event
.
sn
,
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
}
/// [用户操作] 设置设备SN(发送给MCU)—— 持久化
void
_onSnChanged
(
DeviceControlSnChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
sn:
event
.
sn
,
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
sn:
event
.
sn
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 舱内温度控制事件处理 ====================
/// [MCU调用] 更新舱内温度当前值(从MCU获取的真实数据)
void
_onCabinTempCurrentValueFetched
(
DeviceControlCabinTempCurrentValueFetched
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
cabinTemp:
state
.
data
.
cabinTemp
.
copyWith
(
currentValue:
event
.
currentValue
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
}
/// [用户操作] 设置舱内温度设定值(发送给MCU)—— 持久化
void
_onCabinTempSetValueChanged
(
DeviceControlCabinTempSetValueChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
cabinTemp:
state
.
data
.
cabinTemp
.
copyWith
(
setValue:
event
.
setValue
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
cabinTempSetValue:
event
.
setValue
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
/// [用户操作] 设置舱内温度开关(发送给MCU)—— 持久化
void
_onCabinTempSwitchChanged
(
DeviceControlCabinTempSwitchChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
cabinTemp:
state
.
data
.
cabinTemp
.
copyWith
(
isOn:
event
.
isOn
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
cabinTempIsOn:
event
.
isOn
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 舱内湿度控制事件处理 ====================
/// [MCU调用] 更新舱内湿度当前值(从MCU获取的真实数据)
void
_onCabinHumidityCurrentValueFetched
(
DeviceControlCabinHumidityCurrentValueFetched
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
cabinHumidity:
state
.
data
.
cabinHumidity
.
copyWith
(
currentValue:
event
.
currentValue
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
}
/// [用户操作] 设置舱内湿度设定值(发送给MCU)—— 持久化
void
_onCabinHumiditySetValueChanged
(
DeviceControlCabinHumiditySetValueChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
cabinHumidity:
state
.
data
.
cabinHumidity
.
copyWith
(
setValue:
event
.
setValue
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
cabinHumiditySetValue:
event
.
setValue
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
/// [用户操作] 设置舱内湿度开关(发送给MCU)—— 持久化
void
_onCabinHumiditySwitchChanged
(
DeviceControlCabinHumiditySwitchChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
cabinHumidity:
state
.
data
.
cabinHumidity
.
copyWith
(
isOn:
event
.
isOn
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
cabinHumidityIsOn:
event
.
isOn
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 氧气浓度控制事件处理 ====================
/// [MCU调用] 更新氧气浓度当前值(从MCU获取的真实数据)
void
_onOxygenConcentrationCurrentValueFetched
(
DeviceControlOxygenConcentrationCurrentValueFetched
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
oxygenConcentration:
state
.
data
.
oxygenConcentration
.
copyWith
(
currentValue:
event
.
currentValue
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
}
/// [用户操作] 设置氧气浓度设定值(发送给MCU)—— 持久化
void
_onOxygenConcentrationSetValueChanged
(
DeviceControlOxygenConcentrationSetValueChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
oxygenConcentration:
state
.
data
.
oxygenConcentration
.
copyWith
(
setValue:
event
.
setValue
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
oxygenConcentrationSetValue:
event
.
setValue
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
/// [用户操作] 设置氧气浓度开关(发送给MCU)—— 持久化
void
_onOxygenConcentrationSwitchChanged
(
DeviceControlOxygenConcentrationSwitchChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
oxygenConcentration:
state
.
data
.
oxygenConcentration
.
copyWith
(
isOn:
event
.
isOn
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
oxygenConcentrationIsOn:
event
.
isOn
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 二氧化碳浓度控制事件处理 ====================
/// [MCU调用] 更新二氧化碳浓度当前值(从MCU获取的真实数据)
void
_onCO2ConcentrationCurrentValueFetched
(
DeviceControlCO2ConcentrationCurrentValueFetched
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
co2Concentration:
state
.
data
.
co2Concentration
.
copyWith
(
currentValue:
event
.
currentValue
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
}
/// [用户操作] 设置二氧化碳浓度告警阈值(发送给MCU)—— 持久化
void
_onCO2ConcentrationAlarmThresholdChanged
(
DeviceControlCO2ConcentrationAlarmThresholdChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
co2Concentration:
state
.
data
.
co2Concentration
.
copyWith
(
alarmThreshold:
event
.
alarmThreshold
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
co2AlarmThreshold:
event
.
alarmThreshold
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 护理等级控制事件处理 ====================
/// [用户操作] 设置护理等级(发送给MCU)—— 持久化
void
_onCareLevelChanged
(
DeviceControlCareLevelChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
careLevel:
state
.
data
.
careLevel
.
copyWith
(
currentLevel:
event
.
level
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
careLevelValue:
event
.
level
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 新风进化控制事件处理 ====================
/// [用户操作] 设置新风模式(发送给MCU)—— 持久化
void
_onFreshAirModeChanged
(
DeviceControlFreshAirModeChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
freshAir:
state
.
data
.
freshAir
.
copyWith
(
mode:
event
.
mode
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
freshAirModeValue:
event
.
mode
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 风速调节控制事件处理 ====================
/// [用户操作] 设置风速模式(发送给MCU)—— 持久化
void
_onWindSpeedModeChanged
(
DeviceControlWindSpeedModeChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
windSpeed:
state
.
data
.
windSpeed
.
copyWith
(
currentMode:
event
.
mode
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
windSpeedModeValue:
event
.
mode
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 雾化时间设置事件处理 ====================
/// [用户操作] 设置雾化时间(发送给MCU)—— 持久化
void
_onNebulizationTimeChanged
(
DeviceControlNebulizationTimeChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
nebulizationTime:
state
.
data
.
nebulizationTime
.
copyWith
(
setMinutes:
event
.
minutes
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
nebulizationTimeMinutes:
event
.
minutes
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 消毒时间设置事件处理 ====================
/// [用户操作] 设置消毒时间(发送给MCU)—— 持久化
void
_onDisinfectionTimeChanged
(
DeviceControlDisinfectionTimeChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
disinfectionTime:
state
.
data
.
disinfectionTime
.
copyWith
(
setMinutes:
event
.
minutes
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
disinfectionTimeMinutes:
event
.
minutes
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 开放供氧控制事件处理 ====================
/// [用户操作] 设置开放供氧开关(发送给MCU)—— 持久化
void
_onOpenOxygenSwitchChanged
(
DeviceControlOpenOxygenSwitchChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
openOxygen:
state
.
data
.
openOxygen
.
copyWith
(
isOn:
event
.
isOn
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
openOxygenIsOn:
event
.
isOn
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 供氧计时事件处理 ====================
/// [MCU调用] 更新供氧计时(从MCU获取)
void
_onOxygenTimerUpdated
(
DeviceControlOxygenTimerUpdated
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
oxygenTimer:
state
.
data
.
oxygenTimer
.
copyWith
(
hours:
event
.
hours
,
minutes:
event
.
minutes
,
seconds:
event
.
seconds
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
}
/// [用户操作] 清零供氧计时
void
_onOxygenTimerCleared
(
DeviceControlOxygenTimerCleared
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
oxygenTimer:
const
OxygenTimerBO
(
hours:
'00'
,
minutes:
'00'
,
seconds:
'00'
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
// TODO: 发送清零指令到MCU
}
// ==================== 循环模式控制事件处理 ====================
/// [用户操作] 设置循环模式(发送给MCU)—— 持久化
void
_onCirculationModeChanged
(
DeviceControlCirculationModeChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
circulationMode:
state
.
data
.
circulationMode
.
copyWith
(
currentMode:
event
.
mode
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
circulationModeValue:
event
.
mode
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 灯光控制事件处理 ====================
/// [用户操作] 设置检查灯开关(发送给MCU)—— 持久化
void
_onCheckLightSwitchChanged
(
DeviceControlCheckLightSwitchChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
lightControl:
state
.
data
.
lightControl
.
copyWith
(
checkLightOn:
event
.
isOn
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
checkLightOn:
event
.
isOn
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
/// [用户操作] 设置照明灯开关(发送给MCU)—— 持久化
void
_onIlluminationLightSwitchChanged
(
DeviceControlIlluminationLightSwitchChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
lightControl:
state
.
data
.
lightControl
.
copyWith
(
illuminationOn:
event
.
isOn
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
illuminationOn:
event
.
isOn
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
/// [用户操作] 设置蓝光灯开关(发送给MCU)—— 持久化
void
_onBlueLightSwitchChanged
(
DeviceControlBlueLightSwitchChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
lightControl:
state
.
data
.
lightControl
.
copyWith
(
blueLightOn:
event
.
isOn
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
blueLightOn:
event
.
isOn
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
/// [用户操作] 设置红光灯开关(发送给MCU)—— 持久化
void
_onRedLightSwitchChanged
(
DeviceControlRedLightSwitchChanged
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
lightControl:
state
.
data
.
lightControl
.
copyWith
(
redLightOn:
event
.
isOn
,
),
);
emit
(
state
.
copyWith
(
data:
newData
,
userSettings:
state
.
userSettings
.
copyWith
(
redLightOn:
event
.
isOn
),
clearError:
true
,
));
// TODO: 发送设置到MCU
}
// ==================== 全局统计数据事件处理 ====================
/// [MCU调用] 更新总运行时长
void
_onTotalRunTimeUpdated
(
DeviceControlTotalRunTimeUpdated
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
totalRunTime:
event
.
totalRunTime
,
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
}
/// [MCU调用] 更新环境温度
void
_onEnvironmentTempUpdated
(
DeviceControlEnvironmentTempUpdated
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
environmentTemp:
event
.
environmentTemp
,
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
}
/// [MCU调用] 更新总制氧时长
void
_onTotalOxygenTimeUpdated
(
DeviceControlTotalOxygenTimeUpdated
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
final
newData
=
state
.
data
.
copyWith
(
totalOxygenTime:
event
.
totalOxygenTime
,
);
emit
(
state
.
copyWith
(
data:
newData
,
clearError:
true
));
}
/// [用户操作] 重置设备设置为默认值 —— 清除持久化
void
_onResetSettings
(
DeviceControlResetSettings
event
,
Emitter
<
DeviceControlState
>
emit
,
)
{
emit
(
const
DeviceControlState
());
// TODO: 发送重置指令到MCU
}
// ==================== 便捷方法 - 供外部调用 ====================
/// [MCU调用] 更新设备SN
void
updateSn
(
String
?
sn
)
=>
add
(
DeviceControlSnFetched
(
sn
));
/// [用户调用] 设置设备SN
void
setSn
(
String
?
sn
)
=>
add
(
DeviceControlSnChanged
(
sn
));
/// [MCU调用] 更新舱内温度当前值
void
updateCabinTempCurrentValue
(
String
value
)
=>
add
(
DeviceControlCabinTempCurrentValueFetched
(
value
));
/// [用户调用] 设置舱内温度设定值
void
setCabinTempSetValue
(
String
value
)
=>
add
(
DeviceControlCabinTempSetValueChanged
(
value
));
/// [用户调用] 设置舱内温度开关
void
setCabinTempSwitch
(
bool
isOn
)
=>
add
(
DeviceControlCabinTempSwitchChanged
(
isOn
));
/// [MCU调用] 更新舱内湿度当前值
void
updateCabinHumidityCurrentValue
(
String
value
)
=>
add
(
DeviceControlCabinHumidityCurrentValueFetched
(
value
));
/// [用户调用] 设置舱内湿度设定值
void
setCabinHumiditySetValue
(
String
value
)
=>
add
(
DeviceControlCabinHumiditySetValueChanged
(
value
));
/// [用户调用] 设置舱内湿度开关
void
setCabinHumiditySwitch
(
bool
isOn
)
=>
add
(
DeviceControlCabinHumiditySwitchChanged
(
isOn
));
/// [MCU调用] 更新氧气浓度当前值
void
updateOxygenConcentrationCurrentValue
(
String
value
)
=>
add
(
DeviceControlOxygenConcentrationCurrentValueFetched
(
value
));
/// [用户调用] 设置氧气浓度设定值
void
setOxygenConcentrationSetValue
(
String
value
)
=>
add
(
DeviceControlOxygenConcentrationSetValueChanged
(
value
));
/// [用户调用] 设置氧气浓度开关
void
setOxygenConcentrationSwitch
(
bool
isOn
)
=>
add
(
DeviceControlOxygenConcentrationSwitchChanged
(
isOn
));
/// [MCU调用] 更新二氧化碳浓度当前值
void
updateCO2ConcentrationCurrentValue
(
String
value
)
=>
add
(
DeviceControlCO2ConcentrationCurrentValueFetched
(
value
));
/// [用户调用] 设置二氧化碳浓度告警阈值
void
setCO2ConcentrationAlarmThreshold
(
String
value
)
=>
add
(
DeviceControlCO2ConcentrationAlarmThresholdChanged
(
value
));
/// [用户调用] 设置护理等级
void
setCareLevel
(
CareLevel
level
)
=>
add
(
DeviceControlCareLevelChanged
(
level
));
/// [用户调用] 设置新风模式
void
setFreshAirMode
(
FreshAirMode
mode
)
=>
add
(
DeviceControlFreshAirModeChanged
(
mode
));
/// [用户调用] 设置风速模式
void
setWindSpeedMode
(
WindSpeedMode
mode
)
=>
add
(
DeviceControlWindSpeedModeChanged
(
mode
));
/// [用户调用] 设置雾化时间
void
setNebulizationTime
(
String
minutes
)
=>
add
(
DeviceControlNebulizationTimeChanged
(
minutes
));
/// [用户调用] 设置消毒时间
void
setDisinfectionTime
(
String
minutes
)
=>
add
(
DeviceControlDisinfectionTimeChanged
(
minutes
));
/// [用户调用] 设置开放供氧开关
void
setOpenOxygenSwitch
(
bool
isOn
)
=>
add
(
DeviceControlOpenOxygenSwitchChanged
(
isOn
));
/// [MCU调用] 更新供氧计时
void
updateOxygenTimer
(
String
hours
,
String
minutes
,
String
seconds
)
=>
add
(
DeviceControlOxygenTimerUpdated
(
hours
,
minutes
,
seconds
));
/// [用户调用] 清零供氧计时
void
clearOxygenTimer
()
=>
add
(
const
DeviceControlOxygenTimerCleared
());
/// [用户调用] 设置循环模式
void
setCirculationMode
(
CirculationMode
mode
)
=>
add
(
DeviceControlCirculationModeChanged
(
mode
));
/// [用户调用] 设置检查灯开关
void
setCheckLightSwitch
(
bool
isOn
)
=>
add
(
DeviceControlCheckLightSwitchChanged
(
isOn
));
/// [用户调用] 设置照明灯开关
void
setIlluminationLightSwitch
(
bool
isOn
)
=>
add
(
DeviceControlIlluminationLightSwitchChanged
(
isOn
));
/// [用户调用] 设置蓝光灯开关
void
setBlueLightSwitch
(
bool
isOn
)
=>
add
(
DeviceControlBlueLightSwitchChanged
(
isOn
));
/// [用户调用] 设置红光灯开关
void
setRedLightSwitch
(
bool
isOn
)
=>
add
(
DeviceControlRedLightSwitchChanged
(
isOn
));
/// [MCU调用] 更新总运行时长
void
updateTotalRunTime
(
String
time
)
=>
add
(
DeviceControlTotalRunTimeUpdated
(
time
));
/// [MCU调用] 更新环境温度
void
updateEnvironmentTemp
(
String
temp
)
=>
add
(
DeviceControlEnvironmentTempUpdated
(
temp
));
/// [MCU调用] 更新总制氧时长
void
updateTotalOxygenTime
(
String
time
)
=>
add
(
DeviceControlTotalOxygenTimeUpdated
(
time
));
/// [用户调用] 重置设备设置
void
resetSettings
()
=>
add
(
const
DeviceControlResetSettings
());
}
lib/blocs/device_control/device_control_event.dart
0 → 100644
View file @
bccdf520
import
'package:equatable/equatable.dart'
;
import
'package:laki_icu_app/models/bo/device_control_bo.dart'
;
/// 用途:设备控制事件基类
abstract
class
DeviceControlEvent
extends
Equatable
{
const
DeviceControlEvent
();
@override
List
<
Object
?>
get
props
=>
[];
}
// ==================== 基础事件 ====================
/// 加载设备控制数据
class
DeviceControlLoadRequested
extends
DeviceControlEvent
{
const
DeviceControlLoadRequested
();
}
/// 更新设备控制全部数据
class
DeviceControlDataUpdated
extends
DeviceControlEvent
{
final
DeviceControlBO
data
;
const
DeviceControlDataUpdated
(
this
.
data
);
@override
List
<
Object
?>
get
props
=>
[
data
];
}
// ==================== 设备SN事件 ====================
/// 获取设备SN(从MCU获取)
class
DeviceControlSnFetched
extends
DeviceControlEvent
{
final
String
?
sn
;
const
DeviceControlSnFetched
(
this
.
sn
);
@override
List
<
Object
?>
get
props
=>
[
sn
];
}
/// 设置设备SN(用户配置,发送给MCU)
class
DeviceControlSnChanged
extends
DeviceControlEvent
{
final
String
?
sn
;
const
DeviceControlSnChanged
(
this
.
sn
);
@override
List
<
Object
?>
get
props
=>
[
sn
];
}
// ==================== 舱内温度控制事件 ====================
/// 获取舱内温度当前值(从MCU获取)
class
DeviceControlCabinTempCurrentValueFetched
extends
DeviceControlEvent
{
final
String
currentValue
;
const
DeviceControlCabinTempCurrentValueFetched
(
this
.
currentValue
);
@override
List
<
Object
?>
get
props
=>
[
currentValue
];
}
/// 设置舱内温度设定值(用户配置,发送给MCU)
class
DeviceControlCabinTempSetValueChanged
extends
DeviceControlEvent
{
final
String
setValue
;
const
DeviceControlCabinTempSetValueChanged
(
this
.
setValue
);
@override
List
<
Object
?>
get
props
=>
[
setValue
];
}
/// 设置舱内温度开关
class
DeviceControlCabinTempSwitchChanged
extends
DeviceControlEvent
{
final
bool
isOn
;
const
DeviceControlCabinTempSwitchChanged
(
this
.
isOn
);
@override
List
<
Object
?>
get
props
=>
[
isOn
];
}
// ==================== 舱内湿度控制事件 ====================
/// 获取舱内湿度当前值(从MCU获取)
class
DeviceControlCabinHumidityCurrentValueFetched
extends
DeviceControlEvent
{
final
String
currentValue
;
const
DeviceControlCabinHumidityCurrentValueFetched
(
this
.
currentValue
);
@override
List
<
Object
?>
get
props
=>
[
currentValue
];
}
/// 设置舱内湿度设定值(用户配置,发送给MCU)
class
DeviceControlCabinHumiditySetValueChanged
extends
DeviceControlEvent
{
final
String
setValue
;
const
DeviceControlCabinHumiditySetValueChanged
(
this
.
setValue
);
@override
List
<
Object
?>
get
props
=>
[
setValue
];
}
/// 设置舱内湿度开关
class
DeviceControlCabinHumiditySwitchChanged
extends
DeviceControlEvent
{
final
bool
isOn
;
const
DeviceControlCabinHumiditySwitchChanged
(
this
.
isOn
);
@override
List
<
Object
?>
get
props
=>
[
isOn
];
}
// ==================== 氧气浓度控制事件 ====================
/// 获取氧气浓度当前值(从MCU获取)
class
DeviceControlOxygenConcentrationCurrentValueFetched
extends
DeviceControlEvent
{
final
String
currentValue
;
const
DeviceControlOxygenConcentrationCurrentValueFetched
(
this
.
currentValue
);
@override
List
<
Object
?>
get
props
=>
[
currentValue
];
}
/// 设置氧气浓度设定值(用户配置,发送给MCU)
class
DeviceControlOxygenConcentrationSetValueChanged
extends
DeviceControlEvent
{
final
String
setValue
;
const
DeviceControlOxygenConcentrationSetValueChanged
(
this
.
setValue
);
@override
List
<
Object
?>
get
props
=>
[
setValue
];
}
/// 设置氧气浓度开关
class
DeviceControlOxygenConcentrationSwitchChanged
extends
DeviceControlEvent
{
final
bool
isOn
;
const
DeviceControlOxygenConcentrationSwitchChanged
(
this
.
isOn
);
@override
List
<
Object
?>
get
props
=>
[
isOn
];
}
// ==================== 二氧化碳浓度控制事件 ====================
/// 获取二氧化碳浓度当前值(从MCU获取)
class
DeviceControlCO2ConcentrationCurrentValueFetched
extends
DeviceControlEvent
{
final
String
currentValue
;
const
DeviceControlCO2ConcentrationCurrentValueFetched
(
this
.
currentValue
);
@override
List
<
Object
?>
get
props
=>
[
currentValue
];
}
/// 设置二氧化碳浓度告警阈值(用户配置,发送给MCU)
class
DeviceControlCO2ConcentrationAlarmThresholdChanged
extends
DeviceControlEvent
{
final
String
alarmThreshold
;
const
DeviceControlCO2ConcentrationAlarmThresholdChanged
(
this
.
alarmThreshold
);
@override
List
<
Object
?>
get
props
=>
[
alarmThreshold
];
}
// ==================== 护理等级控制事件 ====================
/// 设置护理等级(用户配置,发送给MCU)
class
DeviceControlCareLevelChanged
extends
DeviceControlEvent
{
final
CareLevel
level
;
const
DeviceControlCareLevelChanged
(
this
.
level
);
@override
List
<
Object
?>
get
props
=>
[
level
];
}
// ==================== 新风进化控制事件 ====================
/// 设置新风模式(用户配置,发送给MCU)
class
DeviceControlFreshAirModeChanged
extends
DeviceControlEvent
{
final
FreshAirMode
mode
;
const
DeviceControlFreshAirModeChanged
(
this
.
mode
);
@override
List
<
Object
?>
get
props
=>
[
mode
];
}
// ==================== 风速调节控制事件 ====================
/// 设置风速模式(用户配置,发送给MCU)
class
DeviceControlWindSpeedModeChanged
extends
DeviceControlEvent
{
final
WindSpeedMode
mode
;
const
DeviceControlWindSpeedModeChanged
(
this
.
mode
);
@override
List
<
Object
?>
get
props
=>
[
mode
];
}
// ==================== 雾化时间设置事件 ====================
/// 设置雾化时间(用户配置,发送给MCU)
class
DeviceControlNebulizationTimeChanged
extends
DeviceControlEvent
{
final
String
minutes
;
const
DeviceControlNebulizationTimeChanged
(
this
.
minutes
);
@override
List
<
Object
?>
get
props
=>
[
minutes
];
}
// ==================== 消毒时间设置事件 ====================
/// 设置消毒时间(用户配置,发送给MCU)
class
DeviceControlDisinfectionTimeChanged
extends
DeviceControlEvent
{
final
String
minutes
;
const
DeviceControlDisinfectionTimeChanged
(
this
.
minutes
);
@override
List
<
Object
?>
get
props
=>
[
minutes
];
}
// ==================== 开放供氧控制事件 ====================
/// 设置开放供氧开关(用户配置,发送给MCU)
class
DeviceControlOpenOxygenSwitchChanged
extends
DeviceControlEvent
{
final
bool
isOn
;
const
DeviceControlOpenOxygenSwitchChanged
(
this
.
isOn
);
@override
List
<
Object
?>
get
props
=>
[
isOn
];
}
// ==================== 供氧计时事件 ====================
/// 更新供氧计时(从MCU获取)
class
DeviceControlOxygenTimerUpdated
extends
DeviceControlEvent
{
final
String
hours
;
final
String
minutes
;
final
String
seconds
;
const
DeviceControlOxygenTimerUpdated
(
this
.
hours
,
this
.
minutes
,
this
.
seconds
);
@override
List
<
Object
?>
get
props
=>
[
hours
,
minutes
,
seconds
];
}
/// 清零供氧计时(用户操作)
class
DeviceControlOxygenTimerCleared
extends
DeviceControlEvent
{
const
DeviceControlOxygenTimerCleared
();
}
// ==================== 循环模式控制事件 ====================
/// 设置循环模式(用户配置,发送给MCU)
class
DeviceControlCirculationModeChanged
extends
DeviceControlEvent
{
final
CirculationMode
mode
;
const
DeviceControlCirculationModeChanged
(
this
.
mode
);
@override
List
<
Object
?>
get
props
=>
[
mode
];
}
// ==================== 灯光控制事件 ====================
/// 设置检查灯开关(用户配置,发送给MCU)
class
DeviceControlCheckLightSwitchChanged
extends
DeviceControlEvent
{
final
bool
isOn
;
const
DeviceControlCheckLightSwitchChanged
(
this
.
isOn
);
@override
List
<
Object
?>
get
props
=>
[
isOn
];
}
/// 设置照明灯开关(用户配置,发送给MCU)
class
DeviceControlIlluminationLightSwitchChanged
extends
DeviceControlEvent
{
final
bool
isOn
;
const
DeviceControlIlluminationLightSwitchChanged
(
this
.
isOn
);
@override
List
<
Object
?>
get
props
=>
[
isOn
];
}
/// 设置蓝光灯开关(用户配置,发送给MCU)
class
DeviceControlBlueLightSwitchChanged
extends
DeviceControlEvent
{
final
bool
isOn
;
const
DeviceControlBlueLightSwitchChanged
(
this
.
isOn
);
@override
List
<
Object
?>
get
props
=>
[
isOn
];
}
/// 设置红光灯开关(用户配置,发送给MCU)
class
DeviceControlRedLightSwitchChanged
extends
DeviceControlEvent
{
final
bool
isOn
;
const
DeviceControlRedLightSwitchChanged
(
this
.
isOn
);
@override
List
<
Object
?>
get
props
=>
[
isOn
];
}
// ==================== 全局统计数据事件 ====================
/// 更新总运行时长(从MCU获取)
class
DeviceControlTotalRunTimeUpdated
extends
DeviceControlEvent
{
final
String
totalRunTime
;
const
DeviceControlTotalRunTimeUpdated
(
this
.
totalRunTime
);
@override
List
<
Object
?>
get
props
=>
[
totalRunTime
];
}
/// 更新环境温度(从MCU获取)
class
DeviceControlEnvironmentTempUpdated
extends
DeviceControlEvent
{
final
String
environmentTemp
;
const
DeviceControlEnvironmentTempUpdated
(
this
.
environmentTemp
);
@override
List
<
Object
?>
get
props
=>
[
environmentTemp
];
}
/// 更新总制氧时长(从MCU获取)
class
DeviceControlTotalOxygenTimeUpdated
extends
DeviceControlEvent
{
final
String
totalOxygenTime
;
const
DeviceControlTotalOxygenTimeUpdated
(
this
.
totalOxygenTime
);
@override
List
<
Object
?>
get
props
=>
[
totalOxygenTime
];
}
/// 初始化设备设置(用户操作,重置为默认值)
class
DeviceControlResetSettings
extends
DeviceControlEvent
{
const
DeviceControlResetSettings
();
}
lib/blocs/device_control/device_control_state.dart
0 → 100644
View file @
bccdf520
import
'package:equatable/equatable.dart'
;
import
'package:laki_icu_app/models/bo/device_control_bo.dart'
;
/// 默认的 DeviceControlBO 数据(所有字段为初始值)
const
DeviceControlBO
_defaultDeviceControlBO
=
DeviceControlBO
(
sn:
null
,
totalRunTime:
'0h'
,
environmentTemp:
'25.0℃'
,
totalOxygenTime:
'0h'
,
cabinTemp:
TemperatureControlBO
(
currentValue:
'24'
,
setValue:
'24'
,
unit:
'℃'
,
isOn:
false
,
),
cabinHumidity:
HumidityControlBO
(
currentValue:
'24'
,
setValue:
'50'
,
unit:
'%'
,
isOn:
false
,
),
oxygenConcentration:
OxygenConcentrationBO
(
currentValue:
'24'
,
setValue:
'90'
,
unit:
'%'
,
isOn:
true
,
),
co2Concentration:
CO2ConcentrationBO
(
currentValue:
'2400'
,
alarmThreshold:
'4000'
,
unit:
'PPM'
,
),
careLevel:
CareLevelControlBO
(
currentLevel:
CareLevel
.
special
,
),
freshAir:
FreshAirControlBO
(
mode:
FreshAirMode
.
auto
,
description:
'CO₂超设定值时自动启动外循环净化,当降至2000ppm后,本功能自动关闭'
,
),
windSpeed:
WindSpeedControlBO
(
currentMode:
WindSpeedMode
.
sleep
,
),
nebulizationTime:
NebulizationTimeBO
(
setMinutes:
'00'
,
),
disinfectionTime:
DisinfectionTimeBO
(
setMinutes:
'14'
,
),
openOxygen:
OpenOxygenControlBO
(
isOn:
false
,
description:
'开启后风扇打开,制冷、加热和循环等设备暂停。
\n
*保持设备周围空气相对禁止,严禁烟火'
,
),
oxygenTimer:
OxygenTimerBO
(
hours:
'00'
,
minutes:
'00'
,
seconds:
'00'
,
),
circulationMode:
CirculationModeBO
(
currentMode:
CirculationMode
.
external
,
),
lightControl:
LightControlBO
(
checkLightOn:
false
,
illuminationOn:
false
,
blueLightOn:
false
,
redLightOn:
false
,
),
);
/// 用途:设备控制状态
/// 涉及页面:设备控制页面
class
DeviceControlState
extends
Equatable
{
/// 设备控制数据
final
DeviceControlBO
data
;
/// 用户设置(仅包含用户可配置的字段,用于 hydrated_bloc 持久化)
final
DeviceControlUserSettings
userSettings
;
/// 加载状态
final
bool
isLoading
;
/// 错误信息
final
String
?
error
;
const
DeviceControlState
({
this
.
data
=
_defaultDeviceControlBO
,
this
.
userSettings
=
const
DeviceControlUserSettings
(),
this
.
isLoading
=
false
,
this
.
error
,
});
DeviceControlState
copyWith
({
DeviceControlBO
?
data
,
DeviceControlUserSettings
?
userSettings
,
bool
?
isLoading
,
String
?
error
,
bool
clearError
=
false
,
})
{
return
DeviceControlState
(
data:
data
??
this
.
data
,
userSettings:
userSettings
??
this
.
userSettings
,
isLoading:
isLoading
??
this
.
isLoading
,
error:
clearError
?
null
:
error
??
this
.
error
,
);
}
/// 从持久化存储中恢复状态(仅恢复用户设置,MCU值使用默认值)
factory
DeviceControlState
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
final
userSettings
=
DeviceControlUserSettings
.
fromJson
(
json
);
final
data
=
userSettings
.
applyTo
(
_defaultDeviceControlBO
);
return
DeviceControlState
(
data:
data
,
userSettings:
userSettings
,
);
}
/// 序列化为持久化存储(仅持久化用户设置,不包含MCU获取的值)
Map
<
String
,
dynamic
>
toJson
()
{
return
userSettings
.
toJson
();
}
@override
List
<
Object
?>
get
props
=>
[
data
,
userSettings
,
isLoading
,
error
];
}
lib/main.dart
View file @
bccdf520
...
@@ -3,6 +3,8 @@ import 'package:flutter/foundation.dart';
...
@@ -3,6 +3,8 @@ import 'package:flutter/foundation.dart';
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:hydrated_bloc/hydrated_bloc.dart'
;
import
'package:path_provider/path_provider.dart'
;
import
'package:laki_icu_app/blocs/auth/auth_bloc.dart'
;
import
'package:laki_icu_app/blocs/auth/auth_bloc.dart'
;
import
'package:laki_icu_app/blocs/auth/auth_event.dart'
;
import
'package:laki_icu_app/blocs/auth/auth_event.dart'
;
import
'package:laki_icu_app/blocs/auth/auth_state.dart'
;
import
'package:laki_icu_app/blocs/auth/auth_state.dart'
;
...
@@ -27,10 +29,17 @@ import 'package:flutter_ume_kit_dio_plus/flutter_ume_kit_dio_plus.dart';
...
@@ -27,10 +29,17 @@ import 'package:flutter_ume_kit_dio_plus/flutter_ume_kit_dio_plus.dart';
// import 'package:flutter_ume_kit_show_code_plus/flutter_ume_kit_show_code_plus.dart';
// import 'package:flutter_ume_kit_show_code_plus/flutter_ume_kit_show_code_plus.dart';
import
'package:flutter_ume_kit_ui_plus/flutter_ume_kit_ui_plus.dart'
;
import
'package:flutter_ume_kit_ui_plus/flutter_ume_kit_ui_plus.dart'
;
import
'package:laki_icu_app/blocs/device_control/device_control_bloc.dart'
;
import
'package:marionette_flutter/marionette_flutter.dart'
;
import
'package:marionette_flutter/marionette_flutter.dart'
;
void
main
(
List
<
String
>
args
)
{
Future
<
void
>
main
(
List
<
String
>
args
)
async
{
// WidgetsFlutterBinding.ensureInitialized();
// WidgetsFlutterBinding.ensureInitialized();
// 初始化 HydratedBloc 存储(用于持久化设备控制用户设置等)
WidgetsFlutterBinding
.
ensureInitialized
();
final
storageDirectory
=
await
getApplicationDocumentsDirectory
();
HydratedBloc
.
storage
=
await
HydratedStorage
.
build
(
storageDirectory:
storageDirectory
,
);
// UME 调试工具(仅 Debug 模式启用)
// UME 调试工具(仅 Debug 模式启用)
if
(
kDebugMode
)
{
if
(
kDebugMode
)
{
...
@@ -43,7 +52,6 @@ void main(List<String> args) {
...
@@ -43,7 +52,6 @@ void main(List<String> args) {
// ..register(DioInspector(dio: ApiClient.instance().dio));
// ..register(DioInspector(dio: ApiClient.instance().dio));
runApp
(
UMEWidget
(
enable:
true
,
child:
const
MyApp
()));
runApp
(
UMEWidget
(
enable:
true
,
child:
const
MyApp
()));
}
else
{
}
else
{
WidgetsFlutterBinding
.
ensureInitialized
();
runApp
(
const
MyApp
());
runApp
(
const
MyApp
());
}
}
// runApp(const MyApp());
// runApp(const MyApp());
...
@@ -63,6 +71,7 @@ class _MyAppState extends State<MyApp> {
...
@@ -63,6 +71,7 @@ class _MyAppState extends State<MyApp> {
late
final
AppRouter
_appRouter
;
late
final
AppRouter
_appRouter
;
late
final
AuthBloc
_authBloc
;
late
final
AuthBloc
_authBloc
;
BluetoothReadBloc
?
_bluetoothReadBloc
;
BluetoothReadBloc
?
_bluetoothReadBloc
;
DeviceControlBloc
?
_deviceControlBloc
;
StreamSubscription
?
_tokenExpiredSubscription
;
StreamSubscription
?
_tokenExpiredSubscription
;
bool
_isInitializing
=
true
;
bool
_isInitializing
=
true
;
...
@@ -71,6 +80,9 @@ class _MyAppState extends State<MyApp> {
...
@@ -71,6 +80,9 @@ class _MyAppState extends State<MyApp> {
storageService:
_storageService
,
storageService:
_storageService
,
);
);
DeviceControlBloc
get
_deviceControlBlocInstance
=>
_deviceControlBloc
??=
DeviceControlBloc
();
@override
@override
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
...
@@ -154,6 +166,7 @@ class _MyAppState extends State<MyApp> {
...
@@ -154,6 +166,7 @@ class _MyAppState extends State<MyApp> {
_tokenExpiredSubscription
?.
cancel
();
_tokenExpiredSubscription
?.
cancel
();
_authBloc
.
close
();
_authBloc
.
close
();
_bluetoothReadBloc
?.
close
();
_bluetoothReadBloc
?.
close
();
_deviceControlBloc
?.
close
();
super
.
dispose
();
super
.
dispose
();
}
}
...
@@ -168,6 +181,9 @@ class _MyAppState extends State<MyApp> {
...
@@ -168,6 +181,9 @@ class _MyAppState extends State<MyApp> {
BlocProvider
<
BluetoothReadBloc
>.
value
(
BlocProvider
<
BluetoothReadBloc
>.
value
(
value:
_bluetoothReadBlocInstance
,
value:
_bluetoothReadBlocInstance
,
),
),
BlocProvider
<
DeviceControlBloc
>.
value
(
value:
_deviceControlBlocInstance
,
),
// BlocProvider<CounterBloc>(create: (_) => CounterBloc()),
// BlocProvider<CounterBloc>(create: (_) => CounterBloc()),
],
],
child:
MultiBlocListener
(
child:
MultiBlocListener
(
...
...
lib/models/bo/device_control_bo.dart
0 → 100644
View file @
bccdf520
import
'package:equatable/equatable.dart'
;
/// 用途:设备控制面板整体数据
/// 涉及页面:设备控制页面
class
DeviceControlBO
extends
Equatable
{
// 设备唯一sn
final
String
?
sn
;
/// 总运行时长(设备累计运行时间)
final
String
totalRunTime
;
/// 环境温度(当前环境温度值,从MCU获取)
final
String
environmentTemp
;
/// 总制氧时长(设备累计制氧时间)
final
String
totalOxygenTime
;
/// 舱内温度控制
final
TemperatureControlBO
cabinTemp
;
/// 舱内湿度控制
final
HumidityControlBO
cabinHumidity
;
/// 氧气浓度控制
final
OxygenConcentrationBO
oxygenConcentration
;
/// 二氧化碳浓度控制
final
CO2ConcentrationBO
co2Concentration
;
/// 护理等级控制
final
CareLevelControlBO
careLevel
;
/// 新风进化控制
final
FreshAirControlBO
freshAir
;
/// 风速调节模式
final
WindSpeedControlBO
windSpeed
;
/// 雾化时间设置
final
NebulizationTimeBO
nebulizationTime
;
/// 消毒时间设置
final
DisinfectionTimeBO
disinfectionTime
;
/// 开放供氧控制
final
OpenOxygenControlBO
openOxygen
;
/// 供氧计时
final
OxygenTimerBO
oxygenTimer
;
/// 循环模式控制
final
CirculationModeBO
circulationMode
;
/// 灯光控制
final
LightControlBO
lightControl
;
const
DeviceControlBO
({
this
.
sn
,
required
this
.
totalRunTime
,
required
this
.
environmentTemp
,
required
this
.
totalOxygenTime
,
required
this
.
cabinTemp
,
required
this
.
cabinHumidity
,
required
this
.
oxygenConcentration
,
required
this
.
co2Concentration
,
required
this
.
careLevel
,
required
this
.
freshAir
,
required
this
.
windSpeed
,
required
this
.
nebulizationTime
,
required
this
.
disinfectionTime
,
required
this
.
openOxygen
,
required
this
.
oxygenTimer
,
required
this
.
circulationMode
,
required
this
.
lightControl
,
});
DeviceControlBO
copyWith
({
String
?
sn
,
String
?
totalRunTime
,
String
?
environmentTemp
,
String
?
totalOxygenTime
,
TemperatureControlBO
?
cabinTemp
,
HumidityControlBO
?
cabinHumidity
,
OxygenConcentrationBO
?
oxygenConcentration
,
CO2ConcentrationBO
?
co2Concentration
,
CareLevelControlBO
?
careLevel
,
FreshAirControlBO
?
freshAir
,
WindSpeedControlBO
?
windSpeed
,
NebulizationTimeBO
?
nebulizationTime
,
DisinfectionTimeBO
?
disinfectionTime
,
OpenOxygenControlBO
?
openOxygen
,
OxygenTimerBO
?
oxygenTimer
,
CirculationModeBO
?
circulationMode
,
LightControlBO
?
lightControl
,
})
{
return
DeviceControlBO
(
sn:
sn
??
this
.
sn
,
totalRunTime:
totalRunTime
??
this
.
totalRunTime
,
environmentTemp:
environmentTemp
??
this
.
environmentTemp
,
totalOxygenTime:
totalOxygenTime
??
this
.
totalOxygenTime
,
cabinTemp:
cabinTemp
??
this
.
cabinTemp
,
cabinHumidity:
cabinHumidity
??
this
.
cabinHumidity
,
oxygenConcentration:
oxygenConcentration
??
this
.
oxygenConcentration
,
co2Concentration:
co2Concentration
??
this
.
co2Concentration
,
careLevel:
careLevel
??
this
.
careLevel
,
freshAir:
freshAir
??
this
.
freshAir
,
windSpeed:
windSpeed
??
this
.
windSpeed
,
nebulizationTime:
nebulizationTime
??
this
.
nebulizationTime
,
disinfectionTime:
disinfectionTime
??
this
.
disinfectionTime
,
openOxygen:
openOxygen
??
this
.
openOxygen
,
oxygenTimer:
oxygenTimer
??
this
.
oxygenTimer
,
circulationMode:
circulationMode
??
this
.
circulationMode
,
lightControl:
lightControl
??
this
.
lightControl
,
);
}
factory
DeviceControlBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
DeviceControlBO
(
sn:
json
[
'sn'
]
as
String
?,
totalRunTime:
json
[
'totalRunTime'
]
as
String
?
??
'0h'
,
environmentTemp:
json
[
'environmentTemp'
]
as
String
?
??
'25.0℃'
,
totalOxygenTime:
json
[
'totalOxygenTime'
]
as
String
?
??
'0h'
,
cabinTemp:
json
[
'cabinTemp'
]
!=
null
?
TemperatureControlBO
.
fromJson
(
json
[
'cabinTemp'
]
as
Map
<
String
,
dynamic
>)
:
const
TemperatureControlBO
(
currentValue:
'24'
,
setValue:
'24'
,
unit:
'℃'
,
isOn:
false
,
),
cabinHumidity:
json
[
'cabinHumidity'
]
!=
null
?
HumidityControlBO
.
fromJson
(
json
[
'cabinHumidity'
]
as
Map
<
String
,
dynamic
>)
:
const
HumidityControlBO
(
currentValue:
'24'
,
setValue:
'50'
,
unit:
'%'
,
isOn:
false
,
),
oxygenConcentration:
json
[
'oxygenConcentration'
]
!=
null
?
OxygenConcentrationBO
.
fromJson
(
json
[
'oxygenConcentration'
]
as
Map
<
String
,
dynamic
>)
:
const
OxygenConcentrationBO
(
currentValue:
'24'
,
setValue:
'90'
,
unit:
'%'
,
isOn:
true
,
),
co2Concentration:
json
[
'co2Concentration'
]
!=
null
?
CO2ConcentrationBO
.
fromJson
(
json
[
'co2Concentration'
]
as
Map
<
String
,
dynamic
>)
:
const
CO2ConcentrationBO
(
currentValue:
'2400'
,
alarmThreshold:
'4000'
,
unit:
'PPM'
,
),
careLevel:
json
[
'careLevel'
]
!=
null
?
CareLevelControlBO
.
fromJson
(
json
[
'careLevel'
]
as
Map
<
String
,
dynamic
>)
:
const
CareLevelControlBO
(
currentLevel:
CareLevel
.
special
,
),
freshAir:
json
[
'freshAir'
]
!=
null
?
FreshAirControlBO
.
fromJson
(
json
[
'freshAir'
]
as
Map
<
String
,
dynamic
>)
:
const
FreshAirControlBO
(
mode:
FreshAirMode
.
auto
,
description:
'CO₂超设定值时自动启动外循环净化,当降至2000ppm后,本功能自动关闭'
,
),
windSpeed:
json
[
'windSpeed'
]
!=
null
?
WindSpeedControlBO
.
fromJson
(
json
[
'windSpeed'
]
as
Map
<
String
,
dynamic
>)
:
const
WindSpeedControlBO
(
currentMode:
WindSpeedMode
.
sleep
,
),
nebulizationTime:
json
[
'nebulizationTime'
]
!=
null
?
NebulizationTimeBO
.
fromJson
(
json
[
'nebulizationTime'
]
as
Map
<
String
,
dynamic
>)
:
const
NebulizationTimeBO
(
setMinutes:
'00'
,
),
disinfectionTime:
json
[
'disinfectionTime'
]
!=
null
?
DisinfectionTimeBO
.
fromJson
(
json
[
'disinfectionTime'
]
as
Map
<
String
,
dynamic
>)
:
const
DisinfectionTimeBO
(
setMinutes:
'14'
,
),
openOxygen:
json
[
'openOxygen'
]
!=
null
?
OpenOxygenControlBO
.
fromJson
(
json
[
'openOxygen'
]
as
Map
<
String
,
dynamic
>)
:
const
OpenOxygenControlBO
(
isOn:
false
,
description:
'开启后风扇打开,制冷、加热和循环等设备暂停。
\n
*保持设备周围空气相对禁止,严禁烟火'
,
),
oxygenTimer:
json
[
'oxygenTimer'
]
!=
null
?
OxygenTimerBO
.
fromJson
(
json
[
'oxygenTimer'
]
as
Map
<
String
,
dynamic
>)
:
const
OxygenTimerBO
(
hours:
'00'
,
minutes:
'00'
,
seconds:
'00'
,
),
circulationMode:
json
[
'circulationMode'
]
!=
null
?
CirculationModeBO
.
fromJson
(
json
[
'circulationMode'
]
as
Map
<
String
,
dynamic
>)
:
const
CirculationModeBO
(
currentMode:
CirculationMode
.
external
,
),
lightControl:
json
[
'lightControl'
]
!=
null
?
LightControlBO
.
fromJson
(
json
[
'lightControl'
]
as
Map
<
String
,
dynamic
>)
:
const
LightControlBO
(
checkLightOn:
false
,
illuminationOn:
false
,
blueLightOn:
false
,
redLightOn:
false
,
),
);
}
@override
List
<
Object
?>
get
props
=>
[
sn
,
totalRunTime
,
environmentTemp
,
totalOxygenTime
,
cabinTemp
,
cabinHumidity
,
oxygenConcentration
,
co2Concentration
,
careLevel
,
freshAir
,
windSpeed
,
nebulizationTime
,
disinfectionTime
,
openOxygen
,
oxygenTimer
,
circulationMode
,
lightControl
,
];
}
/// 用途:舱内温度控制数据
/// 涉及页面:设备控制页面
class
TemperatureControlBO
extends
Equatable
{
/// 当前温度值(设备真实数据,从MCU获取)
final
String
currentValue
;
/// 设置温度值(用户配置的期望值)
final
String
setValue
;
/// 温度单位
final
String
unit
;
/// 开关状态
final
bool
isOn
;
const
TemperatureControlBO
({
required
this
.
currentValue
,
required
this
.
setValue
,
required
this
.
unit
,
required
this
.
isOn
,
});
TemperatureControlBO
copyWith
({
String
?
currentValue
,
String
?
setValue
,
String
?
unit
,
bool
?
isOn
,
})
{
return
TemperatureControlBO
(
currentValue:
currentValue
??
this
.
currentValue
,
setValue:
setValue
??
this
.
setValue
,
unit:
unit
??
this
.
unit
,
isOn:
isOn
??
this
.
isOn
,
);
}
factory
TemperatureControlBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
TemperatureControlBO
(
currentValue:
json
[
'currentValue'
]
as
String
?
??
'24'
,
setValue:
json
[
'setValue'
]
as
String
?
??
'24'
,
unit:
json
[
'unit'
]
as
String
?
??
'℃'
,
isOn:
json
[
'isOn'
]
as
bool
?
??
false
,
);
}
@override
List
<
Object
?>
get
props
=>
[
currentValue
,
setValue
,
unit
,
isOn
];
}
/// 用途:舱内湿度控制数据
/// 涉及页面:设备控制页面
class
HumidityControlBO
extends
Equatable
{
/// 当前湿度值(设备真实数据,从MCU获取)
final
String
currentValue
;
/// 设置湿度值(用户配置的期望值)
final
String
setValue
;
/// 湿度单位
final
String
unit
;
/// 开关状态
final
bool
isOn
;
const
HumidityControlBO
({
required
this
.
currentValue
,
required
this
.
setValue
,
required
this
.
unit
,
required
this
.
isOn
,
});
HumidityControlBO
copyWith
({
String
?
currentValue
,
String
?
setValue
,
String
?
unit
,
bool
?
isOn
,
})
{
return
HumidityControlBO
(
currentValue:
currentValue
??
this
.
currentValue
,
setValue:
setValue
??
this
.
setValue
,
unit:
unit
??
this
.
unit
,
isOn:
isOn
??
this
.
isOn
,
);
}
factory
HumidityControlBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
HumidityControlBO
(
currentValue:
json
[
'currentValue'
]
as
String
?
??
'24'
,
setValue:
json
[
'setValue'
]
as
String
?
??
'50'
,
unit:
json
[
'unit'
]
as
String
?
??
'%'
,
isOn:
json
[
'isOn'
]
as
bool
?
??
false
,
);
}
@override
List
<
Object
?>
get
props
=>
[
currentValue
,
setValue
,
unit
,
isOn
];
}
/// 用途:氧气浓度控制数据
/// 涉及页面:设备控制页面
class
OxygenConcentrationBO
extends
Equatable
{
/// 当前浓度值(设备真实数据,从MCU获取)
final
String
currentValue
;
/// 设置浓度值(用户配置的期望值)
final
String
setValue
;
/// 浓度单位
final
String
unit
;
/// 开关状态
final
bool
isOn
;
const
OxygenConcentrationBO
({
required
this
.
currentValue
,
required
this
.
setValue
,
required
this
.
unit
,
required
this
.
isOn
,
});
OxygenConcentrationBO
copyWith
({
String
?
currentValue
,
String
?
setValue
,
String
?
unit
,
bool
?
isOn
,
})
{
return
OxygenConcentrationBO
(
currentValue:
currentValue
??
this
.
currentValue
,
setValue:
setValue
??
this
.
setValue
,
unit:
unit
??
this
.
unit
,
isOn:
isOn
??
this
.
isOn
,
);
}
factory
OxygenConcentrationBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
OxygenConcentrationBO
(
currentValue:
json
[
'currentValue'
]
as
String
?
??
'24'
,
setValue:
json
[
'setValue'
]
as
String
?
??
'90'
,
unit:
json
[
'unit'
]
as
String
?
??
'%'
,
isOn:
json
[
'isOn'
]
as
bool
?
??
true
,
);
}
@override
List
<
Object
?>
get
props
=>
[
currentValue
,
setValue
,
unit
,
isOn
];
}
/// 用途:二氧化碳浓度控制数据
/// 涉及页面:设备控制页面
class
CO2ConcentrationBO
extends
Equatable
{
/// 当前浓度值(设备真实数据,从MCU获取)
final
String
currentValue
;
/// 告警阈值(用户配置的告警触发值)
final
String
alarmThreshold
;
/// 浓度单位
final
String
unit
;
const
CO2ConcentrationBO
({
required
this
.
currentValue
,
required
this
.
alarmThreshold
,
required
this
.
unit
,
});
CO2ConcentrationBO
copyWith
({
String
?
currentValue
,
String
?
alarmThreshold
,
String
?
unit
,
})
{
return
CO2ConcentrationBO
(
currentValue:
currentValue
??
this
.
currentValue
,
alarmThreshold:
alarmThreshold
??
this
.
alarmThreshold
,
unit:
unit
??
this
.
unit
,
);
}
factory
CO2ConcentrationBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
CO2ConcentrationBO
(
currentValue:
json
[
'currentValue'
]
as
String
?
??
'2400'
,
alarmThreshold:
json
[
'alarmThreshold'
]
as
String
?
??
'4000'
,
unit:
json
[
'unit'
]
as
String
?
??
'PPM'
,
);
}
@override
List
<
Object
?>
get
props
=>
[
currentValue
,
alarmThreshold
,
unit
];
}
/// 护理等级枚举
enum
CareLevel
{
off
,
level3
,
level2
,
level1
,
special
}
/// 用途:护理等级控制数据
/// 涉及页面:设备控制页面
class
CareLevelControlBO
extends
Equatable
{
/// 当前护理等级(用户配置的等级)
final
CareLevel
currentLevel
;
const
CareLevelControlBO
({
required
this
.
currentLevel
,
});
CareLevelControlBO
copyWith
({
CareLevel
?
currentLevel
,
})
{
return
CareLevelControlBO
(
currentLevel:
currentLevel
??
this
.
currentLevel
,
);
}
factory
CareLevelControlBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
final
levelStr
=
json
[
'currentLevel'
]
as
String
?
??
'special'
;
final
level
=
CareLevel
.
values
.
firstWhere
(
(
e
)
=>
e
.
name
==
levelStr
,
orElse:
()
=>
CareLevel
.
special
,
);
return
CareLevelControlBO
(
currentLevel:
level
);
}
@override
List
<
Object
?>
get
props
=>
[
currentLevel
];
}
/// 新风模式枚举
enum
FreshAirMode
{
auto
,
on
,
off
}
/// 用途:新风进化控制数据
/// 涉及页面:设备控制页面
class
FreshAirControlBO
extends
Equatable
{
/// 新风模式(用户配置的模式)
final
FreshAirMode
mode
;
/// 模式描述
final
String
description
;
const
FreshAirControlBO
({
required
this
.
mode
,
required
this
.
description
,
});
FreshAirControlBO
copyWith
({
FreshAirMode
?
mode
,
String
?
description
,
})
{
return
FreshAirControlBO
(
mode:
mode
??
this
.
mode
,
description:
description
??
this
.
description
,
);
}
factory
FreshAirControlBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
final
modeStr
=
json
[
'mode'
]
as
String
?
??
'auto'
;
final
mode
=
FreshAirMode
.
values
.
firstWhere
(
(
e
)
=>
e
.
name
==
modeStr
,
orElse:
()
=>
FreshAirMode
.
auto
,
);
return
FreshAirControlBO
(
mode:
mode
,
description:
json
[
'description'
]
as
String
?
??
''
,
);
}
@override
List
<
Object
?>
get
props
=>
[
mode
,
description
];
}
/// 风速模式枚举
enum
WindSpeedMode
{
sleep
,
comfort
,
strong
}
/// 用途:风速调节控制数据
/// 涉及页面:设备控制页面
class
WindSpeedControlBO
extends
Equatable
{
/// 当前风速模式(用户配置的模式)
final
WindSpeedMode
currentMode
;
const
WindSpeedControlBO
({
required
this
.
currentMode
,
});
WindSpeedControlBO
copyWith
({
WindSpeedMode
?
currentMode
,
})
{
return
WindSpeedControlBO
(
currentMode:
currentMode
??
this
.
currentMode
,
);
}
factory
WindSpeedControlBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
final
modeStr
=
json
[
'currentMode'
]
as
String
?
??
'sleep'
;
final
mode
=
WindSpeedMode
.
values
.
firstWhere
(
(
e
)
=>
e
.
name
==
modeStr
,
orElse:
()
=>
WindSpeedMode
.
sleep
,
);
return
WindSpeedControlBO
(
currentMode:
mode
);
}
@override
List
<
Object
?>
get
props
=>
[
currentMode
];
}
/// 用途:雾化时间设置数据
/// 涉及页面:设备控制页面
class
NebulizationTimeBO
extends
Equatable
{
/// 设置雾化分钟数(用户配置的时间)
final
String
setMinutes
;
const
NebulizationTimeBO
({
required
this
.
setMinutes
,
});
NebulizationTimeBO
copyWith
({
String
?
setMinutes
,
})
{
return
NebulizationTimeBO
(
setMinutes:
setMinutes
??
this
.
setMinutes
,
);
}
factory
NebulizationTimeBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
NebulizationTimeBO
(
setMinutes:
json
[
'setMinutes'
]
as
String
?
??
'00'
,
);
}
@override
List
<
Object
?>
get
props
=>
[
setMinutes
];
}
/// 用途:消毒时间设置数据
/// 涉及页面:设备控制页面
class
DisinfectionTimeBO
extends
Equatable
{
/// 设置消毒分钟数(用户配置的时间)
final
String
setMinutes
;
const
DisinfectionTimeBO
({
required
this
.
setMinutes
,
});
DisinfectionTimeBO
copyWith
({
String
?
setMinutes
,
})
{
return
DisinfectionTimeBO
(
setMinutes:
setMinutes
??
this
.
setMinutes
,
);
}
factory
DisinfectionTimeBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
DisinfectionTimeBO
(
setMinutes:
json
[
'setMinutes'
]
as
String
?
??
'14'
,
);
}
@override
List
<
Object
?>
get
props
=>
[
setMinutes
];
}
/// 用途:开放供氧控制数据
/// 涉及页面:设备控制页面
class
OpenOxygenControlBO
extends
Equatable
{
/// 开关状态(用户配置的状态)
final
bool
isOn
;
/// 描述说明
final
String
description
;
const
OpenOxygenControlBO
({
required
this
.
isOn
,
required
this
.
description
,
});
OpenOxygenControlBO
copyWith
({
bool
?
isOn
,
String
?
description
,
})
{
return
OpenOxygenControlBO
(
isOn:
isOn
??
this
.
isOn
,
description:
description
??
this
.
description
,
);
}
factory
OpenOxygenControlBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
OpenOxygenControlBO
(
isOn:
json
[
'isOn'
]
as
bool
?
??
false
,
description:
json
[
'description'
]
as
String
?
??
''
,
);
}
@override
List
<
Object
?>
get
props
=>
[
isOn
,
description
];
}
/// 用途:供氧计时数据
/// 涉及页面:设备控制页面
class
OxygenTimerBO
extends
Equatable
{
/// 小时(当前计时时间)
final
String
hours
;
/// 分钟(当前计时时间)
final
String
minutes
;
/// 秒(当前计时时间)
final
String
seconds
;
const
OxygenTimerBO
({
required
this
.
hours
,
required
this
.
minutes
,
required
this
.
seconds
,
});
OxygenTimerBO
copyWith
({
String
?
hours
,
String
?
minutes
,
String
?
seconds
,
})
{
return
OxygenTimerBO
(
hours:
hours
??
this
.
hours
,
minutes:
minutes
??
this
.
minutes
,
seconds:
seconds
??
this
.
seconds
,
);
}
factory
OxygenTimerBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
OxygenTimerBO
(
hours:
json
[
'hours'
]
as
String
?
??
'00'
,
minutes:
json
[
'minutes'
]
as
String
?
??
'00'
,
seconds:
json
[
'seconds'
]
as
String
?
??
'00'
,
);
}
@override
List
<
Object
?>
get
props
=>
[
hours
,
minutes
,
seconds
];
}
/// 循环模式枚举
enum
CirculationMode
{
external
,
internal
}
/// 用途:循环模式控制数据
/// 涉及页面:设备控制页面
class
CirculationModeBO
extends
Equatable
{
/// 当前循环模式(用户配置的模式)
final
CirculationMode
currentMode
;
const
CirculationModeBO
({
required
this
.
currentMode
,
});
CirculationModeBO
copyWith
({
CirculationMode
?
currentMode
,
})
{
return
CirculationModeBO
(
currentMode:
currentMode
??
this
.
currentMode
,
);
}
factory
CirculationModeBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
final
modeStr
=
json
[
'currentMode'
]
as
String
?
??
'external'
;
final
mode
=
CirculationMode
.
values
.
firstWhere
(
(
e
)
=>
e
.
name
==
modeStr
,
orElse:
()
=>
CirculationMode
.
external
,
);
return
CirculationModeBO
(
currentMode:
mode
);
}
@override
List
<
Object
?>
get
props
=>
[
currentMode
];
}
/// 用途:灯光控制数据
/// 涉及页面:设备控制页面
class
LightControlBO
extends
Equatable
{
/// 检查灯开关(用户配置的状态)
final
bool
checkLightOn
;
/// 照明灯开关(用户配置的状态)
final
bool
illuminationOn
;
/// 蓝光灯开关(用户配置的状态)
final
bool
blueLightOn
;
/// 红光灯开关(用户配置的状态)
final
bool
redLightOn
;
const
LightControlBO
({
required
this
.
checkLightOn
,
required
this
.
illuminationOn
,
required
this
.
blueLightOn
,
required
this
.
redLightOn
,
});
LightControlBO
copyWith
({
bool
?
checkLightOn
,
bool
?
illuminationOn
,
bool
?
blueLightOn
,
bool
?
redLightOn
,
})
{
return
LightControlBO
(
checkLightOn:
checkLightOn
??
this
.
checkLightOn
,
illuminationOn:
illuminationOn
??
this
.
illuminationOn
,
blueLightOn:
blueLightOn
??
this
.
blueLightOn
,
redLightOn:
redLightOn
??
this
.
redLightOn
,
);
}
factory
LightControlBO
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
LightControlBO
(
checkLightOn:
json
[
'checkLightOn'
]
as
bool
?
??
false
,
illuminationOn:
json
[
'illuminationOn'
]
as
bool
?
??
false
,
blueLightOn:
json
[
'blueLightOn'
]
as
bool
?
??
false
,
redLightOn:
json
[
'redLightOn'
]
as
bool
?
??
false
,
);
}
@override
List
<
Object
?>
get
props
=>
[
checkLightOn
,
illuminationOn
,
blueLightOn
,
redLightOn
];
}
/// 用途:设备控制用户设置数据(仅包含用户可配置的字段,不包含MCU获取的值)
/// 用于 hydrated_bloc 持久化
class
DeviceControlUserSettings
extends
Equatable
{
/// 设备SN
final
String
?
sn
;
/// 舱内温度设定值
final
String
?
cabinTempSetValue
;
/// 舱内温度开关
final
bool
?
cabinTempIsOn
;
/// 舱内湿度设定值
final
String
?
cabinHumiditySetValue
;
/// 舱内湿度开关
final
bool
?
cabinHumidityIsOn
;
/// 氧气浓度设定值
final
String
?
oxygenConcentrationSetValue
;
/// 氧气浓度开关
final
bool
?
oxygenConcentrationIsOn
;
/// 二氧化碳告警阈值
final
String
?
co2AlarmThreshold
;
/// 护理等级
final
CareLevel
?
careLevelValue
;
/// 新风模式
final
FreshAirMode
?
freshAirModeValue
;
/// 风速模式
final
WindSpeedMode
?
windSpeedModeValue
;
/// 雾化时间(分钟)
final
String
?
nebulizationTimeMinutes
;
/// 消毒时间(分钟)
final
String
?
disinfectionTimeMinutes
;
/// 开放供氧开关
final
bool
?
openOxygenIsOn
;
/// 循环模式
final
CirculationMode
?
circulationModeValue
;
/// 检查灯开关
final
bool
?
checkLightOn
;
/// 照明灯开关
final
bool
?
illuminationOn
;
/// 蓝光灯开关
final
bool
?
blueLightOn
;
/// 红光灯开关
final
bool
?
redLightOn
;
const
DeviceControlUserSettings
({
this
.
sn
,
this
.
cabinTempSetValue
,
this
.
cabinTempIsOn
,
this
.
cabinHumiditySetValue
,
this
.
cabinHumidityIsOn
,
this
.
oxygenConcentrationSetValue
,
this
.
oxygenConcentrationIsOn
,
this
.
co2AlarmThreshold
,
this
.
careLevelValue
,
this
.
freshAirModeValue
,
this
.
windSpeedModeValue
,
this
.
nebulizationTimeMinutes
,
this
.
disinfectionTimeMinutes
,
this
.
openOxygenIsOn
,
this
.
circulationModeValue
,
this
.
checkLightOn
,
this
.
illuminationOn
,
this
.
blueLightOn
,
this
.
redLightOn
,
});
DeviceControlUserSettings
copyWith
({
String
?
sn
,
String
?
cabinTempSetValue
,
bool
?
cabinTempIsOn
,
String
?
cabinHumiditySetValue
,
bool
?
cabinHumidityIsOn
,
String
?
oxygenConcentrationSetValue
,
bool
?
oxygenConcentrationIsOn
,
String
?
co2AlarmThreshold
,
CareLevel
?
careLevelValue
,
FreshAirMode
?
freshAirModeValue
,
WindSpeedMode
?
windSpeedModeValue
,
String
?
nebulizationTimeMinutes
,
String
?
disinfectionTimeMinutes
,
bool
?
openOxygenIsOn
,
CirculationMode
?
circulationModeValue
,
bool
?
checkLightOn
,
bool
?
illuminationOn
,
bool
?
blueLightOn
,
bool
?
redLightOn
,
})
{
return
DeviceControlUserSettings
(
sn:
sn
??
this
.
sn
,
cabinTempSetValue:
cabinTempSetValue
??
this
.
cabinTempSetValue
,
cabinTempIsOn:
cabinTempIsOn
??
this
.
cabinTempIsOn
,
cabinHumiditySetValue:
cabinHumiditySetValue
??
this
.
cabinHumiditySetValue
,
cabinHumidityIsOn:
cabinHumidityIsOn
??
this
.
cabinHumidityIsOn
,
oxygenConcentrationSetValue:
oxygenConcentrationSetValue
??
this
.
oxygenConcentrationSetValue
,
oxygenConcentrationIsOn:
oxygenConcentrationIsOn
??
this
.
oxygenConcentrationIsOn
,
co2AlarmThreshold:
co2AlarmThreshold
??
this
.
co2AlarmThreshold
,
careLevelValue:
careLevelValue
??
this
.
careLevelValue
,
freshAirModeValue:
freshAirModeValue
??
this
.
freshAirModeValue
,
windSpeedModeValue:
windSpeedModeValue
??
this
.
windSpeedModeValue
,
nebulizationTimeMinutes:
nebulizationTimeMinutes
??
this
.
nebulizationTimeMinutes
,
disinfectionTimeMinutes:
disinfectionTimeMinutes
??
this
.
disinfectionTimeMinutes
,
openOxygenIsOn:
openOxygenIsOn
??
this
.
openOxygenIsOn
,
circulationModeValue:
circulationModeValue
??
this
.
circulationModeValue
,
checkLightOn:
checkLightOn
??
this
.
checkLightOn
,
illuminationOn:
illuminationOn
??
this
.
illuminationOn
,
blueLightOn:
blueLightOn
??
this
.
blueLightOn
,
redLightOn:
redLightOn
??
this
.
redLightOn
,
);
}
/// 将用户设置应用到 DeviceControlBO 上
/// MCU获取的值不受影响,仅覆盖用户可配置的字段
DeviceControlBO
applyTo
(
DeviceControlBO
bo
)
{
return
bo
.
copyWith
(
sn:
sn
??
bo
.
sn
,
cabinTemp:
bo
.
cabinTemp
.
copyWith
(
setValue:
cabinTempSetValue
??
bo
.
cabinTemp
.
setValue
,
isOn:
cabinTempIsOn
??
bo
.
cabinTemp
.
isOn
,
),
cabinHumidity:
bo
.
cabinHumidity
.
copyWith
(
setValue:
cabinHumiditySetValue
??
bo
.
cabinHumidity
.
setValue
,
isOn:
cabinHumidityIsOn
??
bo
.
cabinHumidity
.
isOn
,
),
oxygenConcentration:
bo
.
oxygenConcentration
.
copyWith
(
setValue:
oxygenConcentrationSetValue
??
bo
.
oxygenConcentration
.
setValue
,
isOn:
oxygenConcentrationIsOn
??
bo
.
oxygenConcentration
.
isOn
,
),
co2Concentration:
bo
.
co2Concentration
.
copyWith
(
alarmThreshold:
co2AlarmThreshold
??
bo
.
co2Concentration
.
alarmThreshold
,
),
careLevel:
careLevelValue
!=
null
?
bo
.
careLevel
.
copyWith
(
currentLevel:
careLevelValue
)
:
null
,
freshAir:
freshAirModeValue
!=
null
?
bo
.
freshAir
.
copyWith
(
mode:
freshAirModeValue
)
:
null
,
windSpeed:
windSpeedModeValue
!=
null
?
bo
.
windSpeed
.
copyWith
(
currentMode:
windSpeedModeValue
)
:
null
,
nebulizationTime:
nebulizationTimeMinutes
!=
null
?
bo
.
nebulizationTime
.
copyWith
(
setMinutes:
nebulizationTimeMinutes
)
:
null
,
disinfectionTime:
disinfectionTimeMinutes
!=
null
?
bo
.
disinfectionTime
.
copyWith
(
setMinutes:
disinfectionTimeMinutes
)
:
null
,
openOxygen:
openOxygenIsOn
!=
null
?
bo
.
openOxygen
.
copyWith
(
isOn:
openOxygenIsOn
)
:
null
,
circulationMode:
circulationModeValue
!=
null
?
bo
.
circulationMode
.
copyWith
(
currentMode:
circulationModeValue
)
:
null
,
lightControl:
bo
.
lightControl
.
copyWith
(
checkLightOn:
checkLightOn
??
bo
.
lightControl
.
checkLightOn
,
illuminationOn:
illuminationOn
??
bo
.
lightControl
.
illuminationOn
,
blueLightOn:
blueLightOn
??
bo
.
lightControl
.
blueLightOn
,
redLightOn:
redLightOn
??
bo
.
lightControl
.
redLightOn
,
),
);
}
factory
DeviceControlUserSettings
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
DeviceControlUserSettings
(
sn:
json
[
'sn'
]
as
String
?,
cabinTempSetValue:
json
[
'cabinTempSetValue'
]
as
String
?,
cabinTempIsOn:
json
[
'cabinTempIsOn'
]
as
bool
?,
cabinHumiditySetValue:
json
[
'cabinHumiditySetValue'
]
as
String
?,
cabinHumidityIsOn:
json
[
'cabinHumidityIsOn'
]
as
bool
?,
oxygenConcentrationSetValue:
json
[
'oxygenConcentrationSetValue'
]
as
String
?,
oxygenConcentrationIsOn:
json
[
'oxygenConcentrationIsOn'
]
as
bool
?,
co2AlarmThreshold:
json
[
'co2AlarmThreshold'
]
as
String
?,
careLevelValue:
json
[
'careLevelValue'
]
!=
null
?
CareLevel
.
values
.
firstWhere
(
(
e
)
=>
e
.
name
==
json
[
'careLevelValue'
]
as
String
,
orElse:
()
=>
CareLevel
.
special
,
)
:
null
,
freshAirModeValue:
json
[
'freshAirModeValue'
]
!=
null
?
FreshAirMode
.
values
.
firstWhere
(
(
e
)
=>
e
.
name
==
json
[
'freshAirModeValue'
]
as
String
,
orElse:
()
=>
FreshAirMode
.
auto
,
)
:
null
,
windSpeedModeValue:
json
[
'windSpeedModeValue'
]
!=
null
?
WindSpeedMode
.
values
.
firstWhere
(
(
e
)
=>
e
.
name
==
json
[
'windSpeedModeValue'
]
as
String
,
orElse:
()
=>
WindSpeedMode
.
sleep
,
)
:
null
,
nebulizationTimeMinutes:
json
[
'nebulizationTimeMinutes'
]
as
String
?,
disinfectionTimeMinutes:
json
[
'disinfectionTimeMinutes'
]
as
String
?,
openOxygenIsOn:
json
[
'openOxygenIsOn'
]
as
bool
?,
circulationModeValue:
json
[
'circulationModeValue'
]
!=
null
?
CirculationMode
.
values
.
firstWhere
(
(
e
)
=>
e
.
name
==
json
[
'circulationModeValue'
]
as
String
,
orElse:
()
=>
CirculationMode
.
external
,
)
:
null
,
checkLightOn:
json
[
'checkLightOn'
]
as
bool
?,
illuminationOn:
json
[
'illuminationOn'
]
as
bool
?,
blueLightOn:
json
[
'blueLightOn'
]
as
bool
?,
redLightOn:
json
[
'redLightOn'
]
as
bool
?,
);
}
Map
<
String
,
dynamic
>
toJson
()
{
return
{
if
(
sn
!=
null
)
'sn'
:
sn
,
if
(
cabinTempSetValue
!=
null
)
'cabinTempSetValue'
:
cabinTempSetValue
,
if
(
cabinTempIsOn
!=
null
)
'cabinTempIsOn'
:
cabinTempIsOn
,
if
(
cabinHumiditySetValue
!=
null
)
'cabinHumiditySetValue'
:
cabinHumiditySetValue
,
if
(
cabinHumidityIsOn
!=
null
)
'cabinHumidityIsOn'
:
cabinHumidityIsOn
,
if
(
oxygenConcentrationSetValue
!=
null
)
'oxygenConcentrationSetValue'
:
oxygenConcentrationSetValue
,
if
(
oxygenConcentrationIsOn
!=
null
)
'oxygenConcentrationIsOn'
:
oxygenConcentrationIsOn
,
if
(
co2AlarmThreshold
!=
null
)
'co2AlarmThreshold'
:
co2AlarmThreshold
,
if
(
careLevelValue
!=
null
)
'careLevelValue'
:
careLevelValue
!.
name
,
if
(
freshAirModeValue
!=
null
)
'freshAirModeValue'
:
freshAirModeValue
!.
name
,
if
(
windSpeedModeValue
!=
null
)
'windSpeedModeValue'
:
windSpeedModeValue
!.
name
,
if
(
nebulizationTimeMinutes
!=
null
)
'nebulizationTimeMinutes'
:
nebulizationTimeMinutes
,
if
(
disinfectionTimeMinutes
!=
null
)
'disinfectionTimeMinutes'
:
disinfectionTimeMinutes
,
if
(
openOxygenIsOn
!=
null
)
'openOxygenIsOn'
:
openOxygenIsOn
,
if
(
circulationModeValue
!=
null
)
'circulationModeValue'
:
circulationModeValue
!.
name
,
if
(
checkLightOn
!=
null
)
'checkLightOn'
:
checkLightOn
,
if
(
illuminationOn
!=
null
)
'illuminationOn'
:
illuminationOn
,
if
(
blueLightOn
!=
null
)
'blueLightOn'
:
blueLightOn
,
if
(
redLightOn
!=
null
)
'redLightOn'
:
redLightOn
,
};
}
@override
List
<
Object
?>
get
props
=>
[
sn
,
cabinTempSetValue
,
cabinTempIsOn
,
cabinHumiditySetValue
,
cabinHumidityIsOn
,
oxygenConcentrationSetValue
,
oxygenConcentrationIsOn
,
co2AlarmThreshold
,
careLevelValue
,
freshAirModeValue
,
windSpeedModeValue
,
nebulizationTimeMinutes
,
disinfectionTimeMinutes
,
openOxygenIsOn
,
circulationModeValue
,
checkLightOn
,
illuminationOn
,
blueLightOn
,
redLightOn
,
];
}
pubspec.yaml
View file @
bccdf520
...
@@ -60,6 +60,7 @@ dependencies:
...
@@ -60,6 +60,7 @@ dependencies:
flutter_reactive_ble
:
^5.5.0
flutter_reactive_ble
:
^5.5.0
mqtt_client
:
^10.5.1
mqtt_client
:
^10.5.1
marionette_flutter
:
^0.5.0
marionette_flutter
:
^0.5.0
hydrated_bloc
:
^9.1.5
dev_dependencies
:
dev_dependencies
:
flutter_test
:
flutter_test
:
sdk
:
flutter
sdk
:
flutter
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment