refactor: extract IF and THEN sections into separate methods for better readability

This commit is contained in:
Faris Armoush
2025-04-17 14:38:04 +03:00
parent a0dd128557
commit c46cfb48a8

View File

@ -36,8 +36,70 @@ class SaveRoutineHelper {
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Left side - IF
Expanded(
_buildIfConditions(state, context),
const SizedBox(width: 16),
_buildThenActions(state, context),
],
),
),
_buildDialogFooter(context, state),
],
),
),
);
},
);
},
);
}
static DialogFooter _buildDialogFooter(BuildContext context, RoutineState state) {
return DialogFooter(
onCancel: () => Navigator.pop(context),
onConfirm: () async {
if (state.isAutomation) {
if (state.isUpdate ?? false) {
context.read<RoutineBloc>().add(const UpdateAutomation());
} else {
context.read<RoutineBloc>().add(const CreateAutomationEvent());
}
} else {
if (state.isUpdate ?? false) {
context.read<RoutineBloc>().add(const UpdateScene());
} else {
context.read<RoutineBloc>().add(const CreateSceneEvent());
}
}
Navigator.pop(context);
},
isConfirmEnabled: true,
);
}
static Expanded _buildThenActions(RoutineState state, BuildContext context) {
return Expanded(
child: ListView(
shrinkWrap: true,
children: [
const Text(
'THEN:',
style: TextStyle(
fontSize: 16,
),
),
const SizedBox(height: 8),
...state.thenItems.map((item) {
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
return functionRow(item, context, functions);
}),
],
),
);
}
static Expanded _buildIfConditions(RoutineState state, BuildContext context) {
return Expanded(
child: ListView(
// crossAxisAlignment: CrossAxisAlignment.start,
shrinkWrap: true,
@ -60,73 +122,12 @@ class SaveRoutineHelper {
),
if (state.isAutomation)
...state.ifItems.map((item) {
final functions = state.selectedFunctions[
item['uniqueCustomId']] ??
[];
final functions =
state.selectedFunctions[item['uniqueCustomId']] ?? [];
return functionRow(item, context, functions);
}),
],
),
),
const SizedBox(width: 16),
// Right side - THEN items
Expanded(
child: ListView(
shrinkWrap: true,
children: [
const Text(
'THEN:',
style: TextStyle(
fontSize: 16,
),
),
const SizedBox(height: 8),
...state.thenItems.map((item) {
final functions = state.selectedFunctions[
item['uniqueCustomId']] ??
[];
return functionRow(item, context, functions);
}),
],
),
),
],
),
),
DialogFooter(
onCancel: () => Navigator.pop(context),
onConfirm: () async {
if (state.isAutomation) {
if (state.isUpdate ?? false) {
context
.read<RoutineBloc>()
.add(const UpdateAutomation());
} else {
context
.read<RoutineBloc>()
.add(const CreateAutomationEvent());
}
} else {
if (state.isUpdate ?? false) {
context.read<RoutineBloc>().add(const UpdateScene());
} else {
context
.read<RoutineBloc>()
.add(const CreateSceneEvent());
}
}
Navigator.pop(context);
},
isConfirmEnabled: true,
),
],
),
),
);
},
);
},
);
}