import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.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/bloc/space_tree_bloc.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 createState() => _RoutinesViewState(); } class _RoutinesViewState extends State { @override void initState() { super.initState(); // context.read().add(FetchDevicesInRoutine()); } @override Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { if (state.createRoutineView) { return const CreateNewRoutineView(); } return Row( children: [ Expanded(child: SpaceTreeView( onSelect: () { context.read() ..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( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.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: () { if (context .read() .state .selectedCommunities .length == 1 && context .read() .state .selectedSpaces .length == 1) { context.read().add( (ResetRoutineState()), ); BlocProvider.of(context).add( const CreateNewRoutineViewEvent( createRoutineView: true), ); } else { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text(context .read() .state .selectedSpaces .isEmpty ? 'Please select a space' : 'Please select only one space to proceed'), ), ); // CustomSnackBar.redSnackBar( // context.read().state.selectedSpaces.isEmpty // ? 'Please select a space' // : 'Please select only one space to proceed'); } }, icon: Icons.add, textString: '', ), const SizedBox( height: 15, ), const Expanded(child: FetchRoutineScenesAutomation()), ], ), ), ]), ), ], ); }, ); } }