mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 01:19:40 +00:00
fixed automation
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/scene_listview.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||
@ -21,32 +23,47 @@ class SceneView extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (BuildContext context) => SceneBloc()
|
||||
..add(LoadScenes(HomeCubit.getInstance().selectedSpace?.id ?? '', showInDevice: pageType))
|
||||
..add(LoadScenes(
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '',
|
||||
HomeCubit.getInstance().selectedSpace ??
|
||||
SpaceModel(
|
||||
id: '-1',
|
||||
name: '',
|
||||
community: Community(
|
||||
uuid: '-1',
|
||||
name: '',
|
||||
)),
|
||||
showInDevice: pageType))
|
||||
..add(LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '')),
|
||||
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
if (state is DeleteSceneSuccess) {
|
||||
if (state.success) {
|
||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
||||
HomeCubit.getInstance().selectedSpace!.id!,HomeCubit.getInstance().selectedSpace!,
|
||||
showInDevice: pageType));
|
||||
BlocProvider.of<SceneBloc>(context).add(
|
||||
LoadScenes(HomeCubit.getInstance().selectedSpace!.id!, showInDevice: pageType));
|
||||
BlocProvider.of<SceneBloc>(context)
|
||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id!));
|
||||
LoadAutomation(HomeCubit.getInstance().selectedSpace!.id!));
|
||||
}
|
||||
}
|
||||
if (state is CreateSceneWithTasks) {
|
||||
if (state.success == true) {
|
||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
||||
HomeCubit.getInstance().selectedSpace!.id!,HomeCubit.getInstance().selectedSpace!,
|
||||
showInDevice: pageType));
|
||||
BlocProvider.of<SceneBloc>(context).add(
|
||||
LoadScenes(HomeCubit.getInstance().selectedSpace!.id!, showInDevice: pageType));
|
||||
BlocProvider.of<SceneBloc>(context)
|
||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id!));
|
||||
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
||||
LoadAutomation(HomeCubit.getInstance().selectedSpace!.id!));
|
||||
context
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(const SmartSceneClearEvent());
|
||||
}
|
||||
}
|
||||
return BlocListener<SceneBloc, SceneState>(
|
||||
listener: (context, state) {
|
||||
if (state is SceneTriggerSuccess) {
|
||||
context.showCustomSnackbar(
|
||||
message: 'Scene ${state.sceneName} triggered successfully!');
|
||||
message:
|
||||
'Scene ${state.sceneName} triggered successfully!');
|
||||
}
|
||||
},
|
||||
child: HomeCubit.getInstance().spaces?.isEmpty ?? true
|
||||
@ -83,25 +100,30 @@ class SceneView extends StatelessWidget {
|
||||
child: ListView(
|
||||
children: [
|
||||
Theme(
|
||||
data: ThemeData()
|
||||
.copyWith(dividerColor: Colors.transparent),
|
||||
data: ThemeData().copyWith(
|
||||
dividerColor: Colors.transparent),
|
||||
child: ExpansionTile(
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
tilePadding:
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: 6),
|
||||
initiallyExpanded: true,
|
||||
iconColor: ColorsManager.grayColor,
|
||||
title: const BodyMedium(text: 'Tap to run routines'),
|
||||
title: const BodyMedium(
|
||||
text: 'Tap to run routines'),
|
||||
children: [
|
||||
scenes.isNotEmpty
|
||||
? SceneGrid(
|
||||
scenes: scenes,
|
||||
loadingSceneId: state.loadingSceneId,
|
||||
loadingSceneId:
|
||||
state.loadingSceneId,
|
||||
disablePlayButton: false,
|
||||
loadingStates:
|
||||
state.loadingStates, // Add this line
|
||||
loadingStates: state
|
||||
.loadingStates, // Add this line
|
||||
)
|
||||
: const Center(
|
||||
child: BodyMedium(
|
||||
text: 'No scenes have been added yet',
|
||||
text:
|
||||
'No scenes have been added yet',
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
@ -111,25 +133,30 @@ class SceneView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Theme(
|
||||
data: ThemeData()
|
||||
.copyWith(dividerColor: Colors.transparent),
|
||||
data: ThemeData().copyWith(
|
||||
dividerColor: Colors.transparent),
|
||||
child: ExpansionTile(
|
||||
initiallyExpanded: true,
|
||||
iconColor: ColorsManager.grayColor,
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
title: const BodyMedium(text: 'Automation'),
|
||||
tilePadding:
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: 6),
|
||||
title: const BodyMedium(
|
||||
text: 'Automation'),
|
||||
children: [
|
||||
automationList.isNotEmpty
|
||||
? SceneGrid(
|
||||
scenes: automationList,
|
||||
loadingSceneId: state.loadingSceneId,
|
||||
loadingSceneId:
|
||||
state.loadingSceneId,
|
||||
disablePlayButton: true,
|
||||
loadingStates:
|
||||
state.loadingStates, // Add this line
|
||||
loadingStates: state
|
||||
.loadingStates, // Add this line
|
||||
)
|
||||
: const Center(
|
||||
child: BodyMedium(
|
||||
text: 'No automations have been added yet',
|
||||
text:
|
||||
'No automations have been added yet',
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
|
Reference in New Issue
Block a user