mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-23 11:47:56 +00:00
change string value to enum
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/effective_period_options.dart';
|
||||
|
||||
abstract class EffectPeriodEvent extends Equatable {
|
||||
const EffectPeriodEvent();
|
||||
@@ -8,7 +9,7 @@ abstract class EffectPeriodEvent extends Equatable {
|
||||
}
|
||||
|
||||
class SetPeriod extends EffectPeriodEvent {
|
||||
final String period;
|
||||
final EnumEffectivePeriodOptions period;
|
||||
|
||||
const SetPeriod(this.period);
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/effective_period_options.dart';
|
||||
|
||||
class EffectPeriodState extends Equatable {
|
||||
final String selectedPeriod;
|
||||
final EnumEffectivePeriodOptions selectedPeriod;
|
||||
final List<String> selectedDays;
|
||||
final String? customStartTime;
|
||||
final String? customEndTime;
|
||||
@@ -15,7 +16,7 @@ class EffectPeriodState extends Equatable {
|
||||
|
||||
factory EffectPeriodState.initial() {
|
||||
return const EffectPeriodState(
|
||||
selectedPeriod: 'All Day',
|
||||
selectedPeriod: EnumEffectivePeriodOptions.allDay,
|
||||
selectedDays: [],
|
||||
customStartTime: null,
|
||||
customEndTime: null,
|
||||
@@ -23,7 +24,7 @@ class EffectPeriodState extends Equatable {
|
||||
}
|
||||
|
||||
EffectPeriodState copyWith({
|
||||
String? selectedPeriod,
|
||||
EnumEffectivePeriodOptions? selectedPeriod,
|
||||
List<String>? selectedDays,
|
||||
String? customStartTime,
|
||||
String? customEndTime,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
enum EnumEffectivePeriodOptions {
|
||||
allDay,
|
||||
daytime,
|
||||
night,
|
||||
custom,
|
||||
none,
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/effective_period_options.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
@@ -14,8 +15,8 @@ class EffectPeriodHelper {
|
||||
String selectedEndTime = "23:59";
|
||||
PageController pageController = PageController(initialPage: 0);
|
||||
|
||||
DateTime startDateTime = DateTime(2022, 1, 1, 0, 0); // Fixed 00:00
|
||||
DateTime endDateTime = DateTime(2022, 1, 1, 23, 59); // Fixed 23:59
|
||||
DateTime startDateTime = DateTime(2022, 1, 1, 0, 0);
|
||||
DateTime endDateTime = DateTime(2022, 1, 1, 23, 59);
|
||||
|
||||
context.customAlertDialog(
|
||||
alertBody: SizedBox(
|
||||
@@ -53,7 +54,7 @@ class EffectPeriodHelper {
|
||||
SetCustomTime(selectedStartTime, selectedEndTime),
|
||||
);
|
||||
context.read<EffectPeriodBloc>().add(
|
||||
const SetPeriod('Custom'),
|
||||
const SetPeriod(EnumEffectivePeriodOptions.custom),
|
||||
);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
@@ -129,4 +130,21 @@ class EffectPeriodHelper {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static String formatEnumValue(EnumEffectivePeriodOptions value) {
|
||||
switch (value) {
|
||||
case EnumEffectivePeriodOptions.allDay:
|
||||
return "All Day";
|
||||
case EnumEffectivePeriodOptions.daytime:
|
||||
return "Daytime";
|
||||
case EnumEffectivePeriodOptions.night:
|
||||
return "Night";
|
||||
case EnumEffectivePeriodOptions.custom:
|
||||
return "Custom";
|
||||
case EnumEffectivePeriodOptions.none:
|
||||
return "None";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
|
||||
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/scene/enum/effective_period_options.dart';
|
||||
import 'package:syncrow_app/features/scene/helper/effect_period_helper.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.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';
|
||||
|
||||
@@ -22,15 +23,17 @@ class PeriodOptions extends StatelessWidget {
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
children: [
|
||||
_buildRadioOption(context, 'All Day', '24 Hours'),
|
||||
_buildRadioOption(context, 'Daytime', 'Sunrise to Sunset'),
|
||||
_buildRadioOption(context, 'Night', 'Sunset to Sunrise'),
|
||||
_buildRadioOption(
|
||||
context, EnumEffectivePeriodOptions.allDay, '24 Hours'),
|
||||
_buildRadioOption(context, EnumEffectivePeriodOptions.daytime,
|
||||
'Sunrise to Sunset'),
|
||||
_buildRadioOption(
|
||||
context, EnumEffectivePeriodOptions.night, 'Sunset to Sunrise'),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
onTap: () => showCustomTimePicker(context),
|
||||
title: BodyMedium(
|
||||
title: const BodyMedium(
|
||||
text: 'Custom',
|
||||
fontColor: ColorsManager.primaryColorWithOpacity,
|
||||
),
|
||||
subtitle:
|
||||
state.customStartTime != null && state.customEndTime != null
|
||||
@@ -43,10 +46,14 @@ class PeriodOptions extends StatelessWidget {
|
||||
text: '00:00 AM - 11:59 PM',
|
||||
style: context.bodySmall.copyWith(fontSize: 10),
|
||||
),
|
||||
trailing: Radio<String>(
|
||||
value: 'Custom',
|
||||
trailing: Radio<EnumEffectivePeriodOptions>(
|
||||
value: EnumEffectivePeriodOptions.custom,
|
||||
groupValue: state.selectedPeriod,
|
||||
onChanged: (value) async {},
|
||||
onChanged: (value) async {
|
||||
if (value != null) {
|
||||
context.read<EffectPeriodBloc>().add(SetPeriod(value));
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -56,7 +63,7 @@ class PeriodOptions extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildRadioOption(
|
||||
BuildContext context, String value, String subtitle) {
|
||||
BuildContext context, EnumEffectivePeriodOptions value, String subtitle) {
|
||||
return BlocBuilder<EffectPeriodBloc, EffectPeriodState>(
|
||||
builder: (context, state) {
|
||||
return ListTile(
|
||||
@@ -64,12 +71,12 @@ class PeriodOptions extends StatelessWidget {
|
||||
onTap: () {
|
||||
context.read<EffectPeriodBloc>().add(SetPeriod(value));
|
||||
},
|
||||
title: BodyMedium(text: value),
|
||||
title: BodyMedium(text: EffectPeriodHelper.formatEnumValue(value)),
|
||||
subtitle: BodySmall(
|
||||
text: subtitle,
|
||||
style: context.bodySmall.copyWith(fontSize: 10),
|
||||
),
|
||||
trailing: Radio<String>(
|
||||
trailing: Radio<EnumEffectivePeriodOptions>(
|
||||
value: value,
|
||||
groupValue: state.selectedPeriod,
|
||||
onChanged: (value) {
|
||||
|
||||
Reference in New Issue
Block a user