mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 10:06:16 +00:00
push switch autoaomtion status update
This commit is contained in:
@ -4,12 +4,15 @@ import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_item.
|
||||
class SceneGrid extends StatelessWidget {
|
||||
final List<dynamic> scenes;
|
||||
final String? loadingSceneId;
|
||||
final bool disablePLayButton;
|
||||
final bool disablePlayButton;
|
||||
final Map<String, bool> loadingStates;
|
||||
|
||||
const SceneGrid({
|
||||
required this.scenes,
|
||||
required this.loadingSceneId,
|
||||
required this.disablePlayButton,
|
||||
required this.loadingStates,
|
||||
super.key,
|
||||
required this.disablePLayButton,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -27,10 +30,14 @@ class SceneGrid extends StatelessWidget {
|
||||
itemBuilder: (context, index) {
|
||||
final scene = scenes[index];
|
||||
final isLoading = loadingSceneId == scene.id;
|
||||
final isSwitchLoading = loadingStates[scene.id] ?? false;
|
||||
|
||||
return SceneItem(
|
||||
scene: scene,
|
||||
isLoading: isLoading,
|
||||
disablePLayButton: disablePLayButton);
|
||||
scene: scene,
|
||||
isLoading: isLoading,
|
||||
disablePlayButton: disablePlayButton,
|
||||
isSwitchLoading: isSwitchLoading,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||
import 'package:syncrow_app/features/scene/model/update_automation.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
|
||||
@ -16,13 +19,15 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
class SceneItem extends StatelessWidget {
|
||||
final ScenesModel scene;
|
||||
final bool isLoading;
|
||||
final bool disablePLayButton;
|
||||
final bool isSwitchLoading;
|
||||
final bool disablePlayButton;
|
||||
|
||||
const SceneItem({
|
||||
required this.scene,
|
||||
required this.isLoading,
|
||||
super.key,
|
||||
required this.disablePLayButton,
|
||||
required this.disablePlayButton,
|
||||
required this.isSwitchLoading,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -33,14 +38,14 @@ class SceneItem extends StatelessWidget {
|
||||
context,
|
||||
Routes.sceneTasksRoute,
|
||||
arguments: SceneSettingsRouteArguments(
|
||||
sceneType: disablePLayButton == false
|
||||
sceneType: disablePlayButton == false
|
||||
? CreateSceneEnum.tabToRun.name
|
||||
: CreateSceneEnum.deviceStatusChanges.name,
|
||||
sceneId: scene.id,
|
||||
sceneName: scene.name,
|
||||
),
|
||||
);
|
||||
if (disablePLayButton == false) {
|
||||
if (disablePlayButton == false) {
|
||||
BlocProvider.of<CreateSceneBloc>(context)
|
||||
.add(const SceneTypeEvent(CreateSceneEnum.tabToRun));
|
||||
BlocProvider.of<CreateSceneBloc>(context).add(
|
||||
@ -66,26 +71,45 @@ class SceneItem extends StatelessWidget {
|
||||
Assets.assetsIconsLogo,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
Visibility(
|
||||
visible: disablePLayButton == false,
|
||||
child: IconButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () {
|
||||
context
|
||||
.read<SceneBloc>()
|
||||
.add(SceneTrigger(scene.id, scene.name));
|
||||
},
|
||||
icon: isLoading
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
disablePlayButton == false
|
||||
? IconButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () {
|
||||
context
|
||||
.read<SceneBloc>()
|
||||
.add(SceneTrigger(scene.id, scene.name));
|
||||
},
|
||||
icon: isLoading
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: const Icon(
|
||||
Icons.play_circle,
|
||||
size: 40,
|
||||
color: ColorsManager.greyColor,
|
||||
),
|
||||
)
|
||||
: isSwitchLoading
|
||||
? Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: ColorsManager.primaryColorWithOpacity,
|
||||
),
|
||||
)
|
||||
: const Icon(
|
||||
Icons.play_circle,
|
||||
size: 40,
|
||||
color: ColorsManager.greyColor,
|
||||
: CupertinoSwitch(
|
||||
activeColor: ColorsManager.primaryColor,
|
||||
value: scene.status == 'enable' ? true : false,
|
||||
onChanged: (value) {
|
||||
context.read<SceneBloc>().add(
|
||||
UpdateAutomationStatus(
|
||||
automationStatusUpdate:
|
||||
AutomationStatusUpdate(
|
||||
isEnable: value,
|
||||
unitUuid: HomeCubit.getInstance()
|
||||
.selectedSpace!
|
||||
.id!),
|
||||
automationId: scene.id));
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
Reference in New Issue
Block a user