push fixes to days un-select and temp_current normilization

This commit is contained in:
ashrafzarkanisala
2024-08-05 21:19:07 +03:00
parent 905399f037
commit 33ec234c0d
6 changed files with 109 additions and 70 deletions
@@ -48,12 +48,21 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
}
}
}
if (widget.functionValue != null) {
groupValue = _normalizeValue(widget.functionValue);
if (widget.taskItem.code == 'temp_current') {
if (widget.functionValue != null) {
groupValue = _normalizeValue(
double.tryParse(widget.functionValue.toString()) ??
widget.taskItem.operationalValues[0].minValue);
} else {
groupValue = widget.taskItem.operationalValues[0].minValue;
}
} else {
groupValue =
_normalizeValue(widget.taskItem.operationalValues[0].minValue);
if (widget.functionValue != null) {
groupValue = _normalizeValue(widget.functionValue);
} else {
groupValue =
_normalizeValue(widget.taskItem.operationalValues[0].minValue);
}
}
setState(() {});
@@ -68,14 +77,6 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
);
}
double _normalizeValue(dynamic value) {
if (((widget.taskItem.code == "temp_set" && value > 199) ||
widget.taskItem.code == "temp_current")) {
return (value) / 10;
}
return value.toDouble();
}
int _comparatorToIndex(String? comparator) {
switch (comparator) {
case "<":
@@ -216,7 +217,7 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
: null,
onChanged: (value) {
setState(() {
groupValue = normalizeValue(value);
groupValue = normalizeToDoubleValue(value);
});
context.read<CreateSceneBloc>().add(SelectedValueEvent(
value: _deNormalizeValue(groupValue),
@@ -237,8 +238,16 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
);
}
double normalizeValue(double value) {
return double.parse(value.toStringAsFixed(1));
double _normalizeValue(dynamic value) {
if ((widget.taskItem.code == "temp_set" && value > 199) ||
(widget.taskItem.code == "temp_current" && value >= -99.0)) {
return (value) / 10;
}
return value.toDouble();
}
double? normalizeToDoubleValue(double value) {
return double.tryParse(value.toStringAsFixed(1));
}
double _deNormalizeValue(double? value) {
@@ -19,18 +19,8 @@ class EffectPeriodBottomSheetContent extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Expanded(
// child: TextButton(
// onPressed: () => Navigator.pop(context),
// child: BodySmall(
// text: 'Save',
// style:
// context.bodySmall.copyWith(color: ColorsManager.primaryColorWithOpacity),
// )),
// ),
const Spacer(),
Expanded(
// flex: 2,
child: BodyMedium(
text: 'Effective Period',
fontColor: ColorsManager.primaryColorWithOpacity,
@@ -4,6 +4,9 @@ import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_b
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_state.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class RepeatDays extends StatelessWidget {
const RepeatDays({super.key});
@@ -27,44 +30,63 @@ class RepeatDays extends StatelessWidget {
const SizedBox(width: 8),
BlocBuilder<EffectPeriodBloc, EffectPeriodState>(
builder: (context, state) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: daysMap.entries.map((entry) {
final day = entry.key;
final abbreviation = entry.value;
final dayIndex = _getDayIndex(day);
final isSelected = state.selectedDaysBinary[dayIndex] == '1';
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 3.0),
child: GestureDetector(
onTap: () {
context.read<EffectPeriodBloc>().add(ToggleDay(day));
},
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color:
isSelected ? Colors.grey : Colors.grey.shade300,
width: 1,
),
),
child: CircleAvatar(
radius: 15,
backgroundColor: Colors.white,
child: Text(
abbreviation,
style: TextStyle(
fontSize: 16,
color:
isSelected ? Colors.grey : Colors.grey.shade300,
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: daysMap.entries.map((entry) {
final day = entry.key;
final abbreviation = entry.value;
final dayIndex = _getDayIndex(day);
final isSelected =
state.selectedDaysBinary[dayIndex] == '1';
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 3.0),
child: GestureDetector(
onTap: () {
context.read<EffectPeriodBloc>().add(ToggleDay(day));
},
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: isSelected
? Colors.grey
: Colors.grey.shade300,
width: 1,
),
),
child: CircleAvatar(
radius: 15,
backgroundColor: Colors.white,
child: Text(
abbreviation,
style: TextStyle(
fontSize: 16,
color: isSelected
? Colors.grey
: Colors.grey.shade300,
),
),
),
),
),
),
);
}).toList(),
),
const SizedBox(
height: 8,
),
if (state.selectedDaysBinary == '0000000')
BodySmall(
text: 'At least one day must be selected',
style:
context.bodyMedium.copyWith(color: ColorsManager.red),
),
);
}).toList(),
],
);
},
),