solve bugs

This commit is contained in:
ashrafzarkanisala
2024-08-03 23:48:56 +03:00
parent 84d909a10a
commit 2c6275e26b
5 changed files with 26 additions and 13 deletions
@@ -414,19 +414,10 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
NavigationService.navigatorKey.currentContext!)
.add(SetCustomTime(effectiveTime!.start, effectiveTime!.end));
// Reset all days to not selected before toggling
// Set the days directly from the API response
BlocProvider.of<EffectPeriodBloc>(
NavigationService.navigatorKey.currentContext!)
.add(ResetDays());
// Iterate over the loops and toggle each day
for (int i = 0; i < effectiveTime!.loops.length; i++) {
if (effectiveTime!.loops[i] == '1') {
BlocProvider.of<EffectPeriodBloc>(
NavigationService.navigatorKey.currentContext!)
.add(ToggleDay(_getDayFromIndex(i)));
}
}
.add(SetDays(response.effectiveTime?.loops ?? '1111111'));
emit(AddSceneTask(
automationTasksList: automationTasksList,
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
@@ -14,6 +16,7 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
on<SetCustomTime>(_onSetCustomTime);
on<ResetEffectivePeriod>(_onResetEffectivePeriod);
on<ResetDays>(_onResetDays);
on<SetDays>(_setAllDays);
}
void _onSetPeriod(SetPeriod event, Emitter<EffectPeriodState> emit) {
@@ -120,4 +123,8 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
return days.indexOf(day);
}
FutureOr<void> _setAllDays(SetDays event, Emitter<EffectPeriodState> emit) {
emit(state.copyWith(selectedDaysBinary: event.daysBinary));
}
}
@@ -42,3 +42,9 @@ class ResetDays extends EffectPeriodEvent {
@override
List<Object> get props => [];
}
class SetDays extends EffectPeriodEvent {
final String daysBinary;
const SetDays(this.daysBinary);
}
@@ -57,6 +57,15 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
}
setState(() {});
context.read<CreateSceneBloc>().add(
SelectedValueEvent(
value: _deNormalizeValue(groupValue),
code: widget.taskItem.code,
isAutomation: widget.isAutomation,
comparator: _indexToComparator(selectedToggleIndex),
),
);
}
double _normalizeValue(dynamic value) {
@@ -48,9 +48,9 @@ class ThenAddedTasksContainer extends StatelessWidget
"${duration.inHours}h ${duration.inMinutes.remainder(60)}m ";
} else if (taskItem.code.contains('temp_set') ||
taskItem.code.contains('temp_current')) {
if (taskItem.functionValue != null || taskItem.functionValue != 0) {
if ((taskItem.functionValue != null || taskItem.functionValue != 0)) {
operationValue =
'${((taskItem.functionValue / 10) as double).round().toString()}°C';
'${((taskItem.functionValue / 10) as double).toStringAsFixed(1)}°C';
} else {
operationValue = '0°C';
}