diff --git a/lib/pages/device_managment/all_devices/view/device_managment_page.dart b/lib/pages/device_managment/all_devices/view/device_managment_page.dart index 966d5361..ffc57131 100644 --- a/lib/pages/device_managment/all_devices/view/device_managment_page.dart +++ b/lib/pages/device_managment/all_devices/view/device_managment_page.dart @@ -88,32 +88,31 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout { ); }), rightBody: const NavigateHomeGridView(), - scaffoldBody: CreateNewRoutineView(), - // BlocBuilder( - // builder: (context, state) { - // if (state is SelectedTabState && state.selectedTab) { - // return const RoutinesView(); - // } - // if (state is ShowCreateRoutineState && state.showCreateRoutine) { - // return const CreateNewRoutineView(); - // } + scaffoldBody: BlocBuilder( + builder: (context, state) { + if (state is SelectedTabState && state.selectedTab) { + return const RoutinesView(); + } + if (state is ShowCreateRoutineState && state.showCreateRoutine) { + return const CreateNewRoutineView(); + } - // return BlocBuilder( - // builder: (context, deviceState) { - // if (deviceState is DeviceManagementLoading) { - // return const Center(child: CircularProgressIndicator()); - // } else if (deviceState is DeviceManagementLoaded || - // deviceState is DeviceManagementFiltered) { - // final devices = (deviceState as dynamic).devices ?? - // (deviceState as DeviceManagementFiltered).filteredDevices; + return BlocBuilder( + builder: (context, deviceState) { + if (deviceState is DeviceManagementLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (deviceState is DeviceManagementLoaded || + deviceState is DeviceManagementFiltered) { + final devices = (deviceState as dynamic).devices ?? + (deviceState as DeviceManagementFiltered).filteredDevices; - // return DeviceManagementBody(devices: devices); - // } else { - // return const Center(child: Text('Error fetching Devices')); - // } - // }, - // ); - // }), + return DeviceManagementBody(devices: devices); + } else { + return const Center(child: Text('Error fetching Devices')); + } + }, + ); + }), ), ); } diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart index 0a9e6b0a..481b397e 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart @@ -29,6 +29,7 @@ class RoutineBloc extends Bloc { on(_onEffectiveTimeEvent); on(_onCreateAutomation); on(_onSetRoutineName); + on(_onResetRoutineState); // on(_onRemoveFunction); // on(_onClearFunctions); } @@ -370,4 +371,9 @@ class RoutineBloc extends Bloc { routineName: null, ); } + + FutureOr _onResetRoutineState( + ResetRoutineState event, Emitter emit) { + emit(_resetState()); + } } diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_event.dart b/lib/pages/routiens/bloc/routine_bloc/routine_event.dart index 9337e88e..90ca81ed 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_event.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_event.dart @@ -121,4 +121,7 @@ class SetRoutineName extends RoutineEvent { @override List get props => [name]; } + +class ResetRoutineState extends RoutineEvent {} + class ClearFunctions extends RoutineEvent {} diff --git a/lib/pages/routiens/widgets/routine_dialogs/discard_dialog.dart b/lib/pages/routiens/widgets/routine_dialogs/discard_dialog.dart new file mode 100644 index 00000000..8b22a671 --- /dev/null +++ b/lib/pages/routiens/widgets/routine_dialogs/discard_dialog.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/common/custom_table.dart'; +import 'package:syncrow_web/pages/device_managment/all_devices/bloc/switch_tabs/switch_tabs_bloc.dart'; +import 'package:syncrow_web/pages/home/bloc/home_bloc.dart'; +import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/extension/build_context_x.dart'; + +class DiscardDialog { + static void show(BuildContext context) { + context.customAlertDialog( + alertBody: Container( + height: 150, + padding: const EdgeInsets.all(16), + child: Column( + children: [ + Text( + 'If you close, you will lose all the changes you have made.', + textAlign: TextAlign.center, + style: context.textTheme.bodyMedium!.copyWith( + color: ColorsManager.red, + fontWeight: FontWeight.w400, + fontSize: 14, + ), + ), + const SizedBox( + height: 20, + ), + Text( + 'Are you sure you wish to close?', + style: context.textTheme.bodyMedium!.copyWith( + fontWeight: FontWeight.w400, + color: ColorsManager.grayColor, + ), + ) + ], + )), + title: 'Discard', + titleStyle: context.textTheme.titleLarge!.copyWith( + color: ColorsManager.red, + fontWeight: FontWeight.bold, + ), + onDismissText: "Don’t Close", + onConfirmText: "Close", + onDismissColor: ColorsManager.grayColor, + onConfirmColor: ColorsManager.red.withOpacity(0.8), + onDismiss: () { + Navigator.pop(context); + }, + onConfirm: () { + context.read().add(ResetRoutineState()); + Navigator.pop(context); + BlocProvider.of(context).add( + const CreateNewRoutineViewEvent(false), + ); + BlocProvider.of(context).add( + const TriggerSwitchTabsEvent(true), + ); + }); + } +} diff --git a/lib/pages/routiens/widgets/routine_search_and_buttons.dart b/lib/pages/routiens/widgets/routine_search_and_buttons.dart index 5bf9db8e..026c8702 100644 --- a/lib/pages/routiens/widgets/routine_search_and_buttons.dart +++ b/lib/pages/routiens/widgets/routine_search_and_buttons.dart @@ -4,6 +4,7 @@ import 'package:syncrow_web/pages/common/buttons/default_button.dart'; import 'package:syncrow_web/pages/common/text_field/custom_text_field.dart'; import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/pages/routiens/helper/save_routine_helper.dart'; +import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/discard_dialog.dart'; import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/setting_dialog.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/style.dart'; @@ -96,7 +97,9 @@ class RoutineSearchAndButtons extends StatelessWidget { width: 200, child: Center( child: DefaultButton( - onPressed: () {}, + onPressed: () { + DiscardDialog.show(context); + }, borderRadius: 15, elevation: 0, borderColor: ColorsManager.greyColor, @@ -148,7 +151,16 @@ class RoutineSearchAndButtons extends StatelessWidget { width: 200, child: Center( child: DefaultButton( - onPressed: () {}, + onPressed: () async { + final result = await SettingHelper.showSettingDialog( + context: context, + ); + if (result != null) { + context + .read() + .add(AddSelectedIcon(result)); + } + }, borderRadius: 15, elevation: 0, borderColor: ColorsManager.greyColor, @@ -192,7 +204,9 @@ class RoutineSearchAndButtons extends StatelessWidget { width: 200, child: Center( child: DefaultButton( - onPressed: () {}, + onPressed: () { + SaveRoutineHelper.showSaveRoutineDialog(context); + }, borderRadius: 15, elevation: 0, backgroundColor: ColorsManager.primaryColor, diff --git a/lib/utils/extension/build_context_x.dart b/lib/utils/extension/build_context_x.dart index dbdbb347..0abd16a1 100644 --- a/lib/utils/extension/build_context_x.dart +++ b/lib/utils/extension/build_context_x.dart @@ -23,6 +23,11 @@ extension BuildContextExt on BuildContext { VoidCallback? onDismiss, bool? hideConfirmButton, final double? dialogWidth, + TextStyle? titleStyle, + String? onDismissText, + String? onConfirmText, + Color? onDismissColor, + Color? onConfirmColor, }) { showDialog( context: this, @@ -42,10 +47,11 @@ extension BuildContextExt on BuildContext { /// header widget Text( title, - style: context.textTheme.bodyMedium!.copyWith( - color: ColorsManager.primaryColorWithOpacity, - fontWeight: FontWeight.bold, - ), + style: titleStyle ?? + context.textTheme.bodyMedium!.copyWith( + color: ColorsManager.primaryColorWithOpacity, + fontWeight: FontWeight.bold, + ), ), Padding( padding: const EdgeInsets.symmetric( @@ -79,9 +85,10 @@ extension BuildContextExt on BuildContext { }, child: Center( child: Text( - 'Cancel', - style: context.textTheme.bodyMedium! - .copyWith(color: ColorsManager.greyColor), + onDismissText ?? 'Cancel', + style: context.textTheme.bodyMedium!.copyWith( + color: onDismissColor ?? + ColorsManager.greyColor), ), ), ), @@ -94,9 +101,9 @@ extension BuildContextExt on BuildContext { onTap: onConfirm, child: Center( child: Text( - 'Confirm', + onConfirmText ?? 'Confirm', style: context.textTheme.bodyMedium!.copyWith( - color: + color: onConfirmColor ?? ColorsManager.primaryColorWithOpacity), ), ),