fix last testing bugs

This commit is contained in:
ashrafzarkanisala
2024-08-03 15:15:09 +03:00
parent 2a2e609601
commit 84d909a10a
8 changed files with 99 additions and 55 deletions

View File

@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
@ -29,7 +27,6 @@ class SceneListview extends StatelessWidget {
itemCount: scenes.length,
itemBuilder: (context, index) {
final scene = scenes[index];
final isLoading = loadingSceneId == scene.id;
return Container(
padding: const EdgeInsets.only(right: 10),
child: DefaultContainer(
@ -43,8 +40,15 @@ class SceneListview extends StatelessWidget {
sceneName: scene.name,
),
);
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneClearEvent());
BlocProvider.of<CreateSceneBloc>(context)
.add(FetchSceneTasksEvent(sceneId: scene.id));
.add(const SceneTypeEvent(CreateSceneEnum.tabToRun));
BlocProvider.of<CreateSceneBloc>(context).add(
FetchSceneTasksEvent(
sceneId: scene.id, isAutomation: false));
},
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.4,

View File

@ -95,6 +95,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
// Check and update if the task exists in tempTasksList
for (var element in tempTasksList) {
if (element.code == event.deviceControlModel.code) {
var updatedElement = element.copyWith(
operationName: event.operation,
deviceName: event.deviceName,
@ -115,6 +116,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
updated = true;
break;
}
}
if (!updated) {
/// for smart scene add to view

View File

@ -17,7 +17,8 @@ mixin SceneLogicHelper {
bool isOnlyDelayOrDelayLast(List<SceneStaticFunction> tasks) {
final lastTask = tasks.last;
return tasks.every((task) => task.code == 'delay') ||
lastTask.code == 'delay';
lastTask.code == 'delay' ||
lastTask.deviceId == 'delay';
}
void handleSaveButtonPress(

View File

@ -19,6 +19,7 @@ class SmartAutomationSelectView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final sceneType = context.read<CreateSceneBloc>().sceneType;
final sceneId = ModalRoute.of(context)!.settings.arguments as String;
return DefaultScaffold(
title: "Select Smart Scene",
padding: const EdgeInsets.only(top: 24),
@ -41,7 +42,8 @@ class SmartAutomationSelectView extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Visibility(
visible: sceneType.name == CreateSceneEnum.deviceStatusChanges.name,
visible: sceneType.name ==
CreateSceneEnum.deviceStatusChanges.name,
child: SceneListTile(
assetPath: Assets.handClickIcon,
titleString: "Tap To Run",
@ -58,7 +60,8 @@ class SmartAutomationSelectView extends StatelessWidget {
),
),
Visibility(
visible: sceneType.name == CreateSceneEnum.deviceStatusChanges.name,
visible: sceneType.name ==
CreateSceneEnum.deviceStatusChanges.name,
child: const Divider(
color: ColorsManager.dividerColor,
),
@ -73,7 +76,7 @@ class SmartAutomationSelectView extends StatelessWidget {
),
onPressed: () {
context.customBottomSheet(
child: const SmartEnableAutomation(),
child: SmartEnableAutomation(automationId: sceneId),
);
},
),

View File

@ -17,7 +17,9 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class CustomBottomSheetWidget extends StatelessWidget {
const CustomBottomSheetWidget({
super.key,
required this.sceneId,
});
final String sceneId;
@override
Widget build(BuildContext context) {
@ -68,7 +70,8 @@ class CustomBottomSheetWidget extends StatelessWidget {
color: ColorsManager.greyColor,
),
onPressed: () {
Navigator.pushNamed(context, Routes.smartAutomationSelectRoute);
Navigator.pushNamed(context, Routes.smartAutomationSelectRoute,
arguments: sceneId);
},
),
SceneListTile(

View File

@ -47,7 +47,7 @@ class ThenDefaultContainer extends StatelessWidget {
return GestureDetector(
onTap: isClickable
? () => context.customBottomSheet(
child: const CustomBottomSheetWidget(),
child: CustomBottomSheetWidget(sceneId:sceneId),
)
: null,
child: SvgPicture.asset(
@ -99,7 +99,7 @@ class ThenDefaultContainer extends StatelessWidget {
builder: (context) => const CreateSceneView()));
} else {
context.customBottomSheet(
child: const CustomBottomSheetWidget(),
child: CustomBottomSheetWidget(sceneId: sceneId,),
);
}
},

View File

@ -15,15 +15,19 @@ class SmartSceneSelectAutomationList extends StatefulWidget {
const SmartSceneSelectAutomationList({
super.key,
required this.automationList,
required this.automationId,
});
final List<ScenesModel> automationList;
final String automationId;
@override
State<SmartSceneSelectAutomationList> createState() => _SmartSceneSelectAutomationListState();
State<SmartSceneSelectAutomationList> createState() =>
_SmartSceneSelectAutomationListState();
}
class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomationList> {
class _SmartSceneSelectAutomationListState
extends State<SmartSceneSelectAutomationList> {
final List<Color> colorList = _generateDarkColors(100);
static List<Color> _generateDarkColors(int count) {
@ -31,7 +35,8 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
final colors = <Color>[];
while (colors.length < count) {
final color = Color((random.nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
final color =
Color((random.nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
if (_isDark(color)) {
colors.add(color);
}
@ -40,12 +45,17 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
}
static bool _isDark(Color color) {
final brightness = ((color.red * 299) + (color.green * 587) + (color.blue * 114)) / 1000;
final brightness =
((color.red * 299) + (color.green * 587) + (color.blue * 114)) / 1000;
return brightness < 128;
}
@override
Widget build(BuildContext context) {
// Filter the automation list to exclude the sceneId
final filteredAutomationList = widget.automationList
.where((e) => e.id != widget.automationId.toString())
.toList();
return Column(
mainAxisSize: MainAxisSize.min,
children: [
@ -70,7 +80,8 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
text: 'Automation',
textAlign: TextAlign.center,
style: context.bodyMedium.copyWith(
color: ColorsManager.primaryColorWithOpacity, fontWeight: FontWeight.bold),
color: ColorsManager.primaryColorWithOpacity,
fontWeight: FontWeight.bold),
),
),
),
@ -89,12 +100,15 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
return ListView.builder(
shrinkWrap: true,
itemCount: widget.automationList.length,
itemCount: filteredAutomationList.length,
itemBuilder: (context, index) {
final automation = widget.automationList[index];
final isSelected = smartSceneEnable?.entityId == automation.id;
final automation = filteredAutomationList[index];
final isSelected =
smartSceneEnable?.entityId == automation.id;
final descriptionSelected = isSelected
? (smartSceneEnable?.actionExecutor == 'rule_enable' ? 'Enable' : 'Disable')
? (smartSceneEnable?.actionExecutor == 'rule_enable'
? 'Enable'
: 'Disable')
: automation.status == 'enable'
? 'Enable'
: 'Disable';
@ -128,14 +142,17 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
Navigator.pop(context);
},
onDismiss: () {
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneClearEvent());
Navigator.pop(context);
},
);
},
label: BodyMedium(
text: _capitalizeFirst(descriptionSelected),
style: context.bodyMedium.copyWith(color: ColorsManager.greyColor),
style: context.bodyMedium
.copyWith(color: ColorsManager.greyColor),
),
icon: const Icon(
Icons.arrow_forward_ios_rounded,
@ -162,7 +179,9 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
Navigator.pop(context);
},
onDismiss: () {
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneClearEvent());
Navigator.pop(context);
},
);
@ -198,10 +217,12 @@ class EnableDisableAutomationDialog extends StatefulWidget {
final String type;
@override
State<EnableDisableAutomationDialog> createState() => _EnableDisableAutomationDialogState();
State<EnableDisableAutomationDialog> createState() =>
_EnableDisableAutomationDialogState();
}
class _EnableDisableAutomationDialogState extends State<EnableDisableAutomationDialog> {
class _EnableDisableAutomationDialogState
extends State<EnableDisableAutomationDialog> {
String? groupValue;
final List<SceneOperationalValue> values = [
SceneOperationalValue(
@ -219,9 +240,11 @@ class _EnableDisableAutomationDialogState extends State<EnableDisableAutomationD
@override
void initState() {
super.initState();
groupValue = widget.descriptionSelected == 'Enable' ? 'rule_enable' : 'rule_disable';
groupValue =
widget.descriptionSelected == 'Enable' ? 'rule_enable' : 'rule_disable';
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(SmartSceneEnable(
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(
SmartSceneEnable(
entityId: widget.automationId,
actionExecutor: groupValue!,
sceneORAutomationName: widget.sceneORAutomationName,
@ -252,11 +275,14 @@ class _EnableDisableAutomationDialogState extends State<EnableDisableAutomationD
setState(() {
groupValue = value;
});
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(
context
.read<SmartSceneSelectBloc>()
.add(SmartSceneEnableEvent(
SmartSceneEnable(
entityId: widget.automationId,
actionExecutor: value!,
sceneORAutomationName: widget.sceneORAutomationName,
sceneORAutomationName:
widget.sceneORAutomationName,
type: widget.type,
isAutomation: true),
));
@ -266,7 +292,9 @@ class _EnableDisableAutomationDialogState extends State<EnableDisableAutomationD
setState(() {
groupValue = operation.value;
});
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(
context
.read<SmartSceneSelectBloc>()
.add(SmartSceneEnableEvent(
SmartSceneEnable(
entityId: widget.automationId,
actionExecutor: operation.value,

View File

@ -10,7 +10,9 @@ import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/utils/context_extension.dart';
class SmartEnableAutomation extends StatelessWidget {
const SmartEnableAutomation({super.key});
const SmartEnableAutomation({super.key, required this.automationId});
final String automationId;
@override
Widget build(BuildContext context) {
@ -29,6 +31,7 @@ class SmartEnableAutomation extends StatelessWidget {
}
if (state is SceneLoaded) {
return SmartSceneSelectAutomationList(
automationId: automationId,
automationList: state.automationList);
}
return const SizedBox.shrink();