diff --git a/lib/features/scene/bloc/effective_period/effect_period_bloc.dart b/lib/features/scene/bloc/effective_period/effect_period_bloc.dart index 9b20627..307a950 100644 --- a/lib/features/scene/bloc/effective_period/effect_period_bloc.dart +++ b/lib/features/scene/bloc/effective_period/effect_period_bloc.dart @@ -9,6 +9,16 @@ import 'package:syncrow_app/features/scene/model/create_automation_model.dart'; import 'package:syncrow_app/navigation/navigation_service.dart'; class EffectPeriodBloc extends Bloc { + final daysMap = { + 'Sun': 'S', + 'Mon': 'M', + 'Tue': 'T', + 'Wed': 'W', + 'Thu': 'T', + 'Fri': 'F', + 'Sat': 'S', + }; + EffectPeriodBloc() : super(EffectPeriodState.initial()) { on(_onSetPeriod); on(_onToggleDay); @@ -43,20 +53,17 @@ class EffectPeriodBloc extends Bloc { break; } - BlocProvider.of( - NavigationService.navigatorKey.currentContext!) - .add(EffectiveTimePeriodEvent(EffectiveTime( - start: startTime, end: endTime, loops: state.selectedDaysBinary))); + BlocProvider.of(NavigationService.navigatorKey.currentContext!).add( + EffectiveTimePeriodEvent( + EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary))); emit(state.copyWith( - selectedPeriod: event.period, - customStartTime: startTime, - customEndTime: endTime)); + selectedPeriod: event.period, customStartTime: startTime, customEndTime: endTime)); } void _onToggleDay(ToggleDay event, Emitter emit) { final daysList = state.selectedDaysBinary.split(''); - final dayIndex = _getDayIndex(event.day); + final dayIndex = getDayIndex(event.day); if (daysList[dayIndex] == '1') { daysList[dayIndex] = '0'; } else { @@ -65,9 +72,8 @@ class EffectPeriodBloc extends Bloc { final newDaysBinary = daysList.join(); emit(state.copyWith(selectedDaysBinary: newDaysBinary)); - BlocProvider.of( - NavigationService.navigatorKey.currentContext!) - .add(EffectiveTimePeriodEvent(EffectiveTime( + BlocProvider.of(NavigationService.navigatorKey.currentContext!).add( + EffectiveTimePeriodEvent(EffectiveTime( start: state.customStartTime ?? '00:00', end: state.customEndTime ?? '23:59', loops: newDaysBinary))); @@ -89,37 +95,31 @@ class EffectPeriodBloc extends Bloc { period = EnumEffectivePeriodOptions.custom; } - emit(state.copyWith( - customStartTime: startTime, - customEndTime: endTime, - selectedPeriod: period)); + emit( + state.copyWith(customStartTime: startTime, customEndTime: endTime, selectedPeriod: period)); - BlocProvider.of( - NavigationService.navigatorKey.currentContext!) - .add(EffectiveTimePeriodEvent(EffectiveTime( - start: startTime, end: endTime, loops: state.selectedDaysBinary))); + BlocProvider.of(NavigationService.navigatorKey.currentContext!).add( + EffectiveTimePeriodEvent( + EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary))); } - void _onResetEffectivePeriod( - ResetEffectivePeriod event, Emitter emit) { + void _onResetEffectivePeriod(ResetEffectivePeriod event, Emitter emit) { emit(state.copyWith( selectedPeriod: EnumEffectivePeriodOptions.allDay, customStartTime: '00:00', customEndTime: '23:59', selectedDaysBinary: '1111111')); - BlocProvider.of( - NavigationService.navigatorKey.currentContext!) - .add(EffectiveTimePeriodEvent( - EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'))); + BlocProvider.of(NavigationService.navigatorKey.currentContext!).add( + EffectiveTimePeriodEvent(EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'))); } void _onResetDays(ResetDays event, Emitter emit) { emit(state.copyWith(selectedDaysBinary: '1111111')); } - int _getDayIndex(String day) { - const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; + int getDayIndex(String day) { + const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; return days.indexOf(day); } diff --git a/lib/features/scene/widgets/effective_period_setting/repeat_days.dart b/lib/features/scene/widgets/effective_period_setting/repeat_days.dart index d3e24d5..47d3a01 100644 --- a/lib/features/scene/widgets/effective_period_setting/repeat_days.dart +++ b/lib/features/scene/widgets/effective_period_setting/repeat_days.dart @@ -13,16 +13,7 @@ class RepeatDays extends StatelessWidget { @override Widget build(BuildContext context) { - final daysMap = { - 'Mon': 'M', - 'Tue': 'T', - 'Wed': 'W', - 'Thu': 'T', - 'Fri': 'F', - 'Sat': 'S', - 'Sun': 'S', - }; - + final effectiveBloc = context.read(); return Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -37,25 +28,22 @@ class RepeatDays extends StatelessWidget { children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceAround, - children: daysMap.entries.map((entry) { + children: effectiveBloc.daysMap.entries.map((entry) { final day = entry.key; final abbreviation = entry.value; - final dayIndex = _getDayIndex(day); - final isSelected = - state.selectedDaysBinary[dayIndex] == '1'; + final dayIndex = effectiveBloc.getDayIndex(day); + final isSelected = state.selectedDaysBinary[dayIndex] == '1'; return Padding( padding: const EdgeInsets.symmetric(horizontal: 3.0), child: GestureDetector( onTap: () { - context.read().add(ToggleDay(day)); + effectiveBloc.add(ToggleDay(day)); }, child: Container( decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all( - color: isSelected - ? Colors.grey - : Colors.grey.shade300, + color: isSelected ? Colors.grey : Colors.grey.shade300, width: 1, ), ), @@ -66,9 +54,7 @@ class RepeatDays extends StatelessWidget { abbreviation, style: TextStyle( fontSize: 16, - color: isSelected - ? Colors.grey - : Colors.grey.shade300, + color: isSelected ? Colors.grey : Colors.grey.shade300, ), ), ), @@ -83,8 +69,7 @@ class RepeatDays extends StatelessWidget { if (state.selectedDaysBinary == '0000000') BodySmall( text: 'At least one day must be selected', - style: - context.bodyMedium.copyWith(color: ColorsManager.red), + style: context.bodyMedium.copyWith(color: ColorsManager.red), ), ], ); @@ -93,9 +78,4 @@ class RepeatDays extends StatelessWidget { ], ); } - - int _getDayIndex(String day) { - const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; - return days.indexOf(day); - } } diff --git a/lib/features/scene/widgets/select_smart_scene/smart_tab_run_list.dart b/lib/features/scene/widgets/select_smart_scene/smart_tab_run_list.dart index 502d69d..660b58e 100644 --- a/lib/features/scene/widgets/select_smart_scene/smart_tab_run_list.dart +++ b/lib/features/scene/widgets/select_smart_scene/smart_tab_run_list.dart @@ -93,7 +93,7 @@ class _SmartSceneSelectTabToRunListState extends State() .add(SmartSceneEnableEvent(SmartSceneEnable( entityId: scene.id, - actionExecutor: 'rule_enable', + actionExecutor: 'rule_trigger', sceneORAutomationName: scene.name, type: scene.type, isAutomation: false, @@ -109,7 +109,7 @@ class _SmartSceneSelectTabToRunListState extends State().add(SmartSceneEnableEvent(SmartSceneEnable( entityId: scene.id, - actionExecutor: 'rule_enable', + actionExecutor: 'rule_trigger', sceneORAutomationName: scene.name, type: scene.type, isAutomation: false, diff --git a/pubspec.yaml b/pubspec.yaml index 1532604..9accbfd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev -version: 1.0.2+18 +version: 1.0.2+19 environment: sdk: ">=3.0.6 <4.0.0"