From 246098b83a5a535b80b36debb2a9e9520c6e3efc Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Thu, 5 Dec 2024 12:42:53 +0300 Subject: [PATCH] Read icon from fetch scene api --- .../bloc/routine_bloc/routine_bloc.dart | 3 ++ .../routiens/helper/save_routine_helper.dart | 2 +- .../models/routine_details_model.dart | 52 +++++++++---------- lib/pages/routiens/widgets/dragable_card.dart | 22 ++++---- 4 files changed, 37 insertions(+), 42 deletions(-) diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart index 89781032..a90ea116 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart @@ -758,6 +758,8 @@ class RoutineBloc extends Bloc { thenItems: [], selectedFunctions: {}, scenes: [], + sceneId: '', + automationId: '', automations: [], isLoading: false, errorMessage: '', @@ -1142,6 +1144,7 @@ class RoutineBloc extends Bloc { : action.type == 'automation' ? 'automation' : 'action', + 'icon': action.icon ?? '' }; } diff --git a/lib/pages/routiens/helper/save_routine_helper.dart b/lib/pages/routiens/helper/save_routine_helper.dart index 280c539a..d73a69a7 100644 --- a/lib/pages/routiens/helper/save_routine_helper.dart +++ b/lib/pages/routiens/helper/save_routine_helper.dart @@ -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, diff --git a/lib/pages/routiens/models/routine_details_model.dart b/lib/pages/routiens/models/routine_details_model.dart index 169bd237..8a4a1202 100644 --- a/lib/pages/routiens/models/routine_details_model.dart +++ b/lib/pages/routiens/models/routine_details_model.dart @@ -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.from( - map['conditions'].map((x) => RoutineCondition.fromMap(x))) + ? List.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 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']); } } diff --git a/lib/pages/routiens/widgets/dragable_card.dart b/lib/pages/routiens/widgets/dragable_card.dart index e26d3d12..56961892 100644 --- a/lib/pages/routiens/widgets/dragable_card.dart +++ b/lib/pages/routiens/widgets/dragable_card.dart @@ -32,18 +32,17 @@ class DraggableCard extends StatelessWidget { Widget build(BuildContext context) { return BlocBuilder( 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 deviceFunctions, + Widget _buildCardContent(BuildContext context, List 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();