Read icon from fetch scene api

This commit is contained in:
Abdullah Alassaf
2024-12-05 12:42:53 +03:00
parent 26f50d59dd
commit 246098b83a
4 changed files with 37 additions and 42 deletions

View File

@ -758,6 +758,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
thenItems: [],
selectedFunctions: {},
scenes: [],
sceneId: '',
automationId: '',
automations: [],
isLoading: false,
errorMessage: '',
@ -1142,6 +1144,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
: action.type == 'automation'
? 'automation'
: 'action',
'icon': action.icon ?? ''
};
}

View File

@ -101,7 +101,7 @@ class SaveRoutineHelper {
final functions =
state.selectedFunctions[item['uniqueCustomId']] ?? [];
return ListTile(
leading: item['type'] == 'tap_to_run'
leading: item['type'] == 'tap_to_run' || item['type'] == 'scene'
? Image.memory(
base64Decode(item['icon']),
width: 22,

View File

@ -48,8 +48,7 @@ class RoutineDetailsModel {
spaceUuid: spaceUuid,
automationName: name,
decisionExpr: decisionExpr,
effectiveTime:
effectiveTime ?? EffectiveTime(start: '', end: '', loops: ''),
effectiveTime: effectiveTime ?? EffectiveTime(start: '', end: '', loops: ''),
conditions: conditions?.map((c) => c.toCondition()).toList() ?? [],
actions: actions.map((a) => a.toAutomationAction()).toList(),
);
@ -64,8 +63,7 @@ class RoutineDetailsModel {
if (iconId != null) 'iconUuid': iconId,
if (showInDevice != null) 'showInDevice': showInDevice,
if (effectiveTime != null) 'effectiveTime': effectiveTime!.toMap(),
if (conditions != null)
'conditions': conditions!.map((x) => x.toMap()).toList(),
if (conditions != null) 'conditions': conditions!.map((x) => x.toMap()).toList(),
if (type != null) 'type': type,
if (sceneId != null) 'sceneId': sceneId,
if (automationId != null) 'automationId': automationId,
@ -82,12 +80,10 @@ class RoutineDetailsModel {
),
iconId: map['iconUuid'],
showInDevice: map['showInDevice'],
effectiveTime: map['effectiveTime'] != null
? EffectiveTime.fromMap(map['effectiveTime'])
: null,
effectiveTime:
map['effectiveTime'] != null ? EffectiveTime.fromMap(map['effectiveTime']) : null,
conditions: map['conditions'] != null
? List<RoutineCondition>.from(
map['conditions'].map((x) => RoutineCondition.fromMap(x)))
? List<RoutineCondition>.from(map['conditions'].map((x) => RoutineCondition.fromMap(x)))
: null,
type: map['type'],
sceneId: map['sceneId'],
@ -108,15 +104,16 @@ class RoutineAction {
final RoutineExecutorProperty? executorProperty;
final String productType;
final String? type;
final String? icon;
RoutineAction({
required this.entityId,
required this.actionExecutor,
required this.productType,
this.executorProperty,
this.name,
this.type,
});
RoutineAction(
{required this.entityId,
required this.actionExecutor,
required this.productType,
this.executorProperty,
this.name,
this.type,
this.icon});
CreateSceneAction toCreateSceneAction() {
return CreateSceneAction(
@ -140,22 +137,21 @@ class RoutineAction {
'actionExecutor': actionExecutor,
if (type != null) 'type': type,
if (name != null) 'name': name,
if (executorProperty != null)
'executorProperty': executorProperty!.toMap(),
if (executorProperty != null) 'executorProperty': executorProperty!.toMap(),
};
}
factory RoutineAction.fromMap(Map<String, dynamic> map) {
return RoutineAction(
entityId: map['entityId'] ?? '',
actionExecutor: map['actionExecutor'] ?? '',
productType: map['productType'] ?? '',
name: map['name'] ?? '',
type: map['type'] ?? '',
executorProperty: map['executorProperty'] != null
? RoutineExecutorProperty.fromMap(map['executorProperty'])
: null,
);
entityId: map['entityId'] ?? '',
actionExecutor: map['actionExecutor'] ?? '',
productType: map['productType'] ?? '',
name: map['name'] ?? '',
type: map['type'] ?? '',
executorProperty: map['executorProperty'] != null
? RoutineExecutorProperty.fromMap(map['executorProperty'])
: null,
icon: map['icon']);
}
}

View File

@ -32,18 +32,17 @@ class DraggableCard extends StatelessWidget {
Widget build(BuildContext context) {
return BlocBuilder<RoutineBloc, RoutineState>(
builder: (context, state) {
final deviceFunctions =
state.selectedFunctions[deviceData['uniqueCustomId']] ?? [];
final deviceFunctions = state.selectedFunctions[deviceData['uniqueCustomId']] ?? [];
int index = state.thenItems.indexWhere(
(item) => item['uniqueCustomId'] == deviceData['uniqueCustomId']);
int index = state.thenItems
.indexWhere((item) => item['uniqueCustomId'] == deviceData['uniqueCustomId']);
if (index != -1) {
return _buildCardContent(context, deviceFunctions, padding: padding);
}
int ifIndex = state.ifItems.indexWhere(
(item) => item['uniqueCustomId'] == deviceData['uniqueCustomId']);
int ifIndex = state.ifItems
.indexWhere((item) => item['uniqueCustomId'] == deviceData['uniqueCustomId']);
if (ifIndex != -1) {
return _buildCardContent(context, deviceFunctions, padding: padding);
@ -53,8 +52,7 @@ class DraggableCard extends StatelessWidget {
data: deviceData,
feedback: Transform.rotate(
angle: -0.1,
child:
_buildCardContent(context, deviceFunctions, padding: padding),
child: _buildCardContent(context, deviceFunctions, padding: padding),
),
childWhenDragging: _buildGreyContainer(),
child: _buildCardContent(context, deviceFunctions, padding: padding),
@ -63,8 +61,7 @@ class DraggableCard extends StatelessWidget {
);
}
Widget _buildCardContent(
BuildContext context, List<DeviceFunctionData> deviceFunctions,
Widget _buildCardContent(BuildContext context, List<DeviceFunctionData> deviceFunctions,
{EdgeInsetsGeometry? padding}) {
return Stack(
children: [
@ -93,7 +90,7 @@ class DraggableCard extends StatelessWidget {
),
),
padding: const EdgeInsets.all(8),
child: deviceData['type'] == 'tap_to_run'
child: deviceData['type'] == 'tap_to_run' || deviceData['type'] == 'scene'
? Image.memory(
base64Decode(deviceData['icon']),
)
@ -162,8 +159,7 @@ class DraggableCard extends StatelessWidget {
}
String _formatFunctionValue(DeviceFunctionData function) {
if (function.functionCode == 'temp_set' ||
function.functionCode == 'temp_current') {
if (function.functionCode == 'temp_set' || function.functionCode == 'temp_current') {
return '${(function.value / 10).toStringAsFixed(0)}°C';
} else if (function.functionCode.contains('countdown')) {
final seconds = function.value.toInt();