mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 02:47:54 +00:00
133 lines
6.1 KiB
Dart
133 lines
6.1 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/scene_bloc/scene_bloc.dart';
|
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/create_unit.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
|
import 'package:syncrow_app/generated/assets.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/strings_manager.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: HomeCubit.getInstance().spaces?.isEmpty ?? true
|
|
? const CreateUnitWidget()
|
|
: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const TitleMedium(
|
|
text: StringsManager.routine,
|
|
style: TextStyle(
|
|
fontSize: 32,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
const BodySmall(
|
|
text: StringsManager.tapToRunRoutine,
|
|
),
|
|
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: GridView.builder(
|
|
shrinkWrap: true,
|
|
gridDelegate:
|
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
mainAxisSpacing: 12,
|
|
crossAxisSpacing: 12,
|
|
childAspectRatio: 1.5,
|
|
),
|
|
itemCount: state.scenes.length,
|
|
itemBuilder: (context, index) {
|
|
final scene = state.scenes[index];
|
|
return DefaultContainer(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.center,
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Image.asset(
|
|
height: 32,
|
|
width: 32,
|
|
Assets.assetsIconsLogo,
|
|
fit: BoxFit.fill,
|
|
),
|
|
BlocBuilder<SceneBloc, SceneState>(
|
|
builder: (context, state) {
|
|
return IconButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: () {
|
|
// context
|
|
// .read<SceneBloc>()
|
|
// .add(SceneTrigger(scene.id));
|
|
},
|
|
icon: state is SceneTriggerLoading
|
|
? const Center(
|
|
child:
|
|
CircularProgressIndicator())
|
|
: const Icon(
|
|
Icons.play_circle,
|
|
size: 40,
|
|
color:
|
|
ColorsManager.greyColor,
|
|
),
|
|
);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 10,
|
|
),
|
|
BodyMedium(
|
|
text: scene.name,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.fade,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 16,
|
|
)
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|