mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
101 lines
4.4 KiB
Dart
101 lines
4.4 KiB
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/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';
|
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_grid_view.dart';
|
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_header.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/create_unit.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
|
import 'package:syncrow_app/utils/context_extension.dart';
|
|
|
|
class SceneView extends StatelessWidget {
|
|
final bool pageType;
|
|
const SceneView({super.key, this.pageType = false});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider(
|
|
create: (BuildContext context) => SceneBloc()
|
|
..add(LoadScenes(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!));
|
|
}
|
|
}
|
|
if (state is CreateSceneWithTasks) {
|
|
if (state.success == true) {
|
|
BlocProvider.of<SceneBloc>(context)
|
|
.add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!));
|
|
}
|
|
}
|
|
return BlocListener<SceneBloc, SceneState>(
|
|
listener: (context, state) {
|
|
if (state is SceneTriggerSuccess) {
|
|
context.showCustomSnackbar(
|
|
message:
|
|
'Scene ${state.sceneName} triggered successfully!');
|
|
}
|
|
},
|
|
child: HomeCubit.getInstance().spaces?.isEmpty ?? true
|
|
? const CreateUnitWidget()
|
|
: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
if (pageType == false) const SceneHeader(),
|
|
if (pageType == false) const SizedBox(height: 8),
|
|
BlocBuilder<SceneBloc, SceneState>(
|
|
builder: (context, state) {
|
|
if (state is SceneLoading) {
|
|
return const Center(
|
|
child: CircularProgressIndicator(),
|
|
);
|
|
}
|
|
if (state is SceneError) {
|
|
return Center(
|
|
child: Text(state.message),
|
|
);
|
|
}
|
|
if (state is SceneLoaded) {
|
|
if (state.scenes.isNotEmpty) {
|
|
return pageType == false
|
|
? Expanded(
|
|
child: SceneGrid(
|
|
scenes: state.scenes,
|
|
loadingSceneId: state.loadingSceneId,
|
|
),
|
|
)
|
|
: Expanded(
|
|
child: SceneListview(
|
|
scenes: state.scenes,
|
|
loadingSceneId: state.loadingSceneId,
|
|
)
|
|
);
|
|
} else {
|
|
return const Expanded(
|
|
child: Center(
|
|
child: BodyMedium(
|
|
text: 'No scenes have been added yet',
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|