mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 10:06:16 +00:00
66 lines
2.5 KiB
Dart
66 lines
2.5 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/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/utils/context_extension.dart';
|
|
|
|
class SceneView extends StatelessWidget {
|
|
const SceneView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider(
|
|
create: (BuildContext context) => SceneBloc()
|
|
..add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!)),
|
|
child: 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: [
|
|
const SceneHeader(),
|
|
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) {
|
|
return Expanded(
|
|
child: SceneGrid(
|
|
scenes: state.scenes,
|
|
loadingSceneId: state.loadingSceneId,
|
|
),
|
|
);
|
|
}
|
|
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|