mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
104 lines
4.0 KiB
Dart
104 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_event.dart';
|
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
|
import 'package:syncrow_web/pages/routines/create_new_routines/create_new_routines.dart';
|
|
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
|
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/fetch_routine_scenes_automation.dart';
|
|
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_view_card.dart';
|
|
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
|
|
import 'package:syncrow_web/utils/color_manager.dart';
|
|
|
|
class RoutinesView extends StatefulWidget {
|
|
const RoutinesView({super.key});
|
|
|
|
@override
|
|
State<RoutinesView> createState() => _RoutinesViewState();
|
|
}
|
|
|
|
class _RoutinesViewState extends State<RoutinesView> {
|
|
void _handleRoutineCreation(BuildContext context) async {
|
|
final result = await showDialog<Map<String, dynamic>>(
|
|
context: context,
|
|
builder: (context) => const CreateNewRoutinesDialog(),
|
|
);
|
|
|
|
if (result == null) return;
|
|
final communityId = result['community'];
|
|
final spaceId = result['space'];
|
|
final _bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
|
final routineBloc = context.read<RoutineBloc>();
|
|
_bloc.add(SaveCommunityIdAndSpaceIdEvent(
|
|
communityID: communityId, spaceID: spaceId));
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
routineBloc.add(const CreateNewRoutineViewEvent(createRoutineView: true));
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
BlocProvider.of<CreateRoutineBloc>(context).add(const ResetSelectedEvent());
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
|
builder: (context, state) {
|
|
if (state.createRoutineView) {
|
|
return const CreateNewRoutineView();
|
|
}
|
|
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: SpaceTreeView(
|
|
onSelect: () => context.read<RoutineBloc>()
|
|
..add(const LoadScenes())
|
|
..add(const LoadAutomation()),
|
|
),
|
|
),
|
|
Expanded(
|
|
flex: 4,
|
|
child: ListView(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(16),
|
|
height: MediaQuery.sizeOf(context).height,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
"Create New Routines",
|
|
style:
|
|
Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
color: ColorsManager.grayColor,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
RoutineViewCard(
|
|
isLoading: false,
|
|
onChanged: (v) {},
|
|
status: '',
|
|
spaceId: '',
|
|
automationId: '',
|
|
communityId: '',
|
|
sceneId: '',
|
|
cardType: '',
|
|
spaceName: '',
|
|
onTap: () => _handleRoutineCreation(context),
|
|
icon: Icons.add,
|
|
textString: '',
|
|
),
|
|
const SizedBox(height: 15),
|
|
const Expanded(child: FetchRoutineScenesAutomation()),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|