merge code

This commit is contained in:
ashraf_personal
2024-11-27 01:19:51 +03:00
9 changed files with 540 additions and 585 deletions

View File

@ -2,10 +2,7 @@ import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_event.dart';
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart';
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
import 'package:syncrow_web/utils/constants/app_enum.dart';
import 'package:syncrow_web/utils/navigation_service.dart';
class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
final daysMap = {
@ -52,10 +49,6 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
break;
}
BlocProvider.of<RoutineBloc>(NavigationService.navigatorKey.currentContext!).add(
EffectiveTimePeriodEvent(
EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary)));
emit(state.copyWith(
selectedPeriod: event.period, customStartTime: startTime, customEndTime: endTime));
}
@ -70,12 +63,6 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
}
final newDaysBinary = daysList.join();
emit(state.copyWith(selectedDaysBinary: newDaysBinary));
BlocProvider.of<RoutineBloc>(NavigationService.navigatorKey.currentContext!).add(
EffectiveTimePeriodEvent(EffectiveTime(
start: state.customStartTime ?? '00:00',
end: state.customEndTime ?? '23:59',
loops: newDaysBinary)));
}
void _onSetCustomTime(SetCustomTime event, Emitter<EffectPeriodState> emit) {
@ -96,10 +83,6 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
emit(
state.copyWith(customStartTime: startTime, customEndTime: endTime, selectedPeriod: period));
BlocProvider.of<RoutineBloc>(NavigationService.navigatorKey.currentContext!).add(
EffectiveTimePeriodEvent(
EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary)));
}
void _onResetEffectivePeriod(ResetEffectivePeriod event, Emitter<EffectPeriodState> emit) {
@ -108,9 +91,6 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
customStartTime: '00:00',
customEndTime: '23:59',
selectedDaysBinary: '1111111'));
BlocProvider.of<RoutineBloc>(NavigationService.navigatorKey.currentContext!).add(
EffectiveTimePeriodEvent(EffectiveTime(start: '00:00', end: '23:59', loops: '1111111')));
}
void _onResetDays(ResetDays event, Emitter<EffectPeriodState> emit) {

View File

@ -35,8 +35,18 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
}
void _onAddToIfContainer(AddToIfContainer event, Emitter<RoutineState> emit) {
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems)
..add(event.item);
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems);
// Find the index of the item in teh current itemsList
int index = updatedIfItems.indexWhere(
(map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
// Replace the map if the index is valid
if (index != -1) {
updatedIfItems[index] = event.item;
} else {
updatedIfItems.add(event.item);
}
if (event.isTabToRun) {
emit(state.copyWith(
ifItems: updatedIfItems, isTabToRun: true, isAutomation: false));
@ -68,13 +78,36 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
try {
if (event.functions.isEmpty) return;
final currentSelectedFunctions =
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
List<DeviceFunctionData> selectedFunction =
List<DeviceFunctionData>.from(event.functions);
Map<String, List<DeviceFunctionData>> currentSelectedFunctions =
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
if (currentSelectedFunctions.containsKey(event.uniqueCustomId)) {
List<DeviceFunctionData> currentFunctions =
List<DeviceFunctionData>.from(
currentSelectedFunctions[event.uniqueCustomId] ?? []);
List<String> functionCode = [];
for (int i = 0; i < selectedFunction.length; i++) {
for (int j = 0; j < currentFunctions.length; j++) {
if (selectedFunction[i].functionCode ==
currentFunctions[j].functionCode) {
currentFunctions[j] = selectedFunction[i];
if (!functionCode.contains(currentFunctions[j].functionCode)) {
functionCode.add(currentFunctions[j].functionCode);
}
}
}
}
for (int i = 0; i < functionCode.length; i++) {
selectedFunction
.removeWhere((code) => code.functionCode == functionCode[i]);
}
currentSelectedFunctions[event.uniqueCustomId] =
List.from(currentSelectedFunctions[event.uniqueCustomId]!)
..addAll(event.functions);
List.from(currentFunctions)..addAll(selectedFunction);
} else {
currentSelectedFunctions[event.uniqueCustomId] =
List.from(event.functions);
@ -324,12 +357,22 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
RemoveDragCard event, Emitter<RoutineState> emit) {
if (event.isFromThen) {
final thenItems = List<Map<String, dynamic>>.from(state.thenItems);
final selectedFunctions =
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
thenItems.removeAt(event.index);
emit(state.copyWith(thenItems: thenItems));
selectedFunctions.remove(event.key);
emit(state.copyWith(
thenItems: thenItems, selectedFunctions: selectedFunctions));
} else {
final ifItems = List<Map<String, dynamic>>.from(state.ifItems);
final selectedFunctions =
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
ifItems.removeAt(event.index);
emit(state.copyWith(ifItems: ifItems));
selectedFunctions.remove(event.key);
emit(state.copyWith(
ifItems: ifItems, selectedFunctions: selectedFunctions));
}
}
@ -342,7 +385,6 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
FutureOr<void> _onEffectiveTimeEvent(
EffectiveTimePeriodEvent event, Emitter<RoutineState> emit) {
debugPrint(event.effectiveTime.toString());
emit(state.copyWith(effectiveTime: event.effectiveTime));
}

View File

@ -82,9 +82,11 @@ class CreateSceneEvent extends RoutineEvent {
class RemoveDragCard extends RoutineEvent {
final int index;
final bool isFromThen;
const RemoveDragCard({required this.index, required this.isFromThen});
final String key;
const RemoveDragCard(
{required this.index, required this.isFromThen, required this.key});
@override
List<Object> get props => [index];
List<Object> get props => [index, isFromThen, key];
}
class ChangeAutomationOperator extends RoutineEvent {

View File

@ -1,6 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart';
import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/effictive_period_dialog.dart';
import 'package:syncrow_web/pages/routiens/widgets/period_option.dart';
import 'package:syncrow_web/pages/routiens/widgets/repeat_days.dart';
@ -11,9 +9,7 @@ class EffectivePeriodView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => EffectPeriodBloc(),
child: Padding(
return Padding(
padding: const EdgeInsets.all(16.0),
child: ListView(
children: [
@ -44,7 +40,6 @@ class EffectivePeriodView extends StatelessWidget {
const SizedBox(height: 24),
],
),
),
);
}
}

View File

@ -26,9 +26,7 @@ class IfContainer extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('IF',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold)),
const Text('IF', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
if (state.isAutomation)
AutomationOperatorSelector(
selectedOperator: state.selectedAutomationOperator),
@ -52,20 +50,38 @@ class IfContainer extends StatelessWidget {
runSpacing: 8,
children: List.generate(
state.ifItems.length,
(index) => DraggableCard(
imagePath:
state.ifItems[index]['imagePath'] ?? '',
(index) => GestureDetector(
onTap: () async {
if (!state.isTabToRun) {
final result = await DeviceDialogHelper.showDeviceDialog(
context, state.ifItems[index]);
if (result != null) {
context
.read<RoutineBloc>()
.add(AddToIfContainer(state.ifItems[index], false));
} else if (!['AC', '1G', '2G', '3G']
.contains(state.ifItems[index]['productType'])) {
context
.read<RoutineBloc>()
.add(AddToIfContainer(state.ifItems[index], false));
}
}
},
child: DraggableCard(
imagePath: state.ifItems[index]['imagePath'] ?? '',
title: state.ifItems[index]['title'] ?? '',
deviceData: state.ifItems[index],
padding: const EdgeInsets.symmetric(
horizontal: 4, vertical: 8),
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
isFromThen: false,
isFromIf: true,
onRemove: () {
context.read<RoutineBloc>().add(
RemoveDragCard(
index: index, isFromThen: false));
context.read<RoutineBloc>().add(RemoveDragCard(
index: index,
isFromThen: false,
key: state.ifItems[index]['uniqueCustomId']));
},
),
)),
),
],
@ -81,22 +97,14 @@ class IfContainer extends StatelessWidget {
if (!state.isTabToRun) {
if (mutableData['deviceId'] == 'tab_to_run') {
context
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, true));
context.read<RoutineBloc>().add(AddToIfContainer(mutableData, true));
} else {
final result = await DeviceDialogHelper.showDeviceDialog(
context, mutableData);
final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData);
if (result != null) {
context
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, false));
} else if (!['AC', '1G', '2G', '3G']
.contains(mutableData['productType'])) {
context
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, false));
context.read<RoutineBloc>().add(AddToIfContainer(mutableData, false));
} else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) {
context.read<RoutineBloc>().add(AddToIfContainer(mutableData, false));
}
}
}
@ -136,15 +144,12 @@ class AutomationOperatorSelector extends StatelessWidget {
child: Text(
'Any condition is met',
style: context.textTheme.bodyMedium?.copyWith(
color: selectedOperator == 'or'
? ColorsManager.whiteColors
: ColorsManager.blackColor,
color:
selectedOperator == 'or' ? ColorsManager.whiteColors : ColorsManager.blackColor,
),
),
onPressed: () {
context
.read<RoutineBloc>()
.add(const ChangeAutomationOperator(operator: 'or'));
context.read<RoutineBloc>().add(const ChangeAutomationOperator(operator: 'or'));
},
),
Container(
@ -170,9 +175,7 @@ class AutomationOperatorSelector extends StatelessWidget {
),
),
onPressed: () {
context
.read<RoutineBloc>()
.add(const ChangeAutomationOperator(operator: 'and'));
context.read<RoutineBloc>().add(const ChangeAutomationOperator(operator: 'and'));
},
),
],

View File

@ -21,12 +21,9 @@ class PeriodOptions extends StatelessWidget {
builder: (context, state) {
return Column(
children: [
_buildRadioOption(
context, EnumEffectivePeriodOptions.allDay, '24 Hours'),
_buildRadioOption(context, EnumEffectivePeriodOptions.daytime,
'Sunrise to Sunset'),
_buildRadioOption(
context, EnumEffectivePeriodOptions.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),
@ -37,8 +34,7 @@ class PeriodOptions extends StatelessWidget {
fontWeight: FontWeight.w400,
fontSize: 14),
),
subtitle: state.customStartTime != null &&
state.customEndTime != null
subtitle: state.customStartTime != null && state.customEndTime != null
? Text(
'${"${state.customStartTime}"} - ${"${state.customEndTime}"}',
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
@ -83,9 +79,7 @@ class PeriodOptions extends StatelessWidget {
subtitle: Text(
subtitle,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: ColorsManager.textPrimaryColor,
fontWeight: FontWeight.w400,
fontSize: 10),
color: ColorsManager.textPrimaryColor, fontWeight: FontWeight.w400, fontSize: 10),
),
trailing: Radio<EnumEffectivePeriodOptions>(
value: value,

View File

@ -1,9 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart';
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart';
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_bloc.dart';
import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_event.dart';
import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_state.dart';
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
import 'package:syncrow_web/pages/routiens/models/icon_model.dart';
import 'package:syncrow_web/pages/routiens/view/effective_period_view.dart';
import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
@ -19,24 +22,29 @@ class SettingHelper {
context: context,
builder: (BuildContext context) {
final isAutomation = context.read<RoutineBloc>().state.isAutomation;
return BlocProvider(
create: (_) =>
SettingBloc()..add(InitialEvent(selectedIcon: iconId ?? '')),
return MultiBlocProvider(
providers: [
BlocProvider(
create: (_) => EffectPeriodBloc(),
),
BlocProvider(
create: (_) => SettingBloc()..add(InitialEvent(selectedIcon: iconId ?? ''))),
],
child: AlertDialog(
contentPadding: EdgeInsets.zero,
content: BlocBuilder<SettingBloc, SettingState>(
builder: (context, state) {
content: BlocBuilder<EffectPeriodBloc, EffectPeriodState>(
builder: (context, effectPeriodState) {
return BlocBuilder<SettingBloc, SettingState>(
builder: (context, settingState) {
String selectedIcon = '';
List<IconModel> list = [];
if (state is TabToRunSettingLoaded) {
selectedIcon = state.selectedIcon;
list = state.iconList;
if (settingState is TabToRunSettingLoaded) {
selectedIcon = settingState.selectedIcon;
list = settingState.iconList;
}
return Container(
width: context.read<SettingBloc>().isExpanded ? 800 : 400,
height: context.read<SettingBloc>().isExpanded && isAutomation
? 500
: 300,
height: context.read<SettingBloc>().isExpanded && isAutomation ? 500 : 300,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
@ -59,18 +67,14 @@ class SettingHelper {
children: [
Container(
padding: const EdgeInsets.only(
top: 10,
left: 10,
right: 10,
bottom: 10),
top: 10, left: 10, right: 10, bottom: 10),
child: Column(
children: [
InkWell(
onTap: () {},
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
MainAxisAlignment.spaceBetween,
children: [
Text(
'Validity',
@ -78,18 +82,14 @@ class SettingHelper {
.textTheme
.bodyMedium!
.copyWith(
color: ColorsManager
.textPrimaryColor,
fontWeight:
FontWeight
.w400,
color:
ColorsManager.textPrimaryColor,
fontWeight: FontWeight.w400,
fontSize: 14),
),
const Icon(
Icons
.arrow_forward_ios_outlined,
color: ColorsManager
.textGray,
Icons.arrow_forward_ios_outlined,
color: ColorsManager.textGray,
size: 15,
)
],
@ -106,18 +106,15 @@ class SettingHelper {
),
InkWell(
onTap: () {
BlocProvider.of<SettingBloc>(
context)
.add(FetchIcons(
BlocProvider.of<SettingBloc>(context).add(
FetchIcons(
expanded: !context
.read<
SettingBloc>()
.read<SettingBloc>()
.isExpanded));
},
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
MainAxisAlignment.spaceBetween,
children: [
Text(
'Effective Period',
@ -125,18 +122,14 @@ class SettingHelper {
.textTheme
.bodyMedium!
.copyWith(
color: ColorsManager
.textPrimaryColor,
fontWeight:
FontWeight
.w400,
color:
ColorsManager.textPrimaryColor,
fontWeight: FontWeight.w400,
fontSize: 14),
),
const Icon(
Icons
.arrow_forward_ios_outlined,
color: ColorsManager
.textGray,
Icons.arrow_forward_ios_outlined,
color: ColorsManager.textGray,
size: 15,
)
],
@ -152,9 +145,7 @@ class SettingHelper {
height: 5,
),
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Executed by',
@ -162,10 +153,8 @@ class SettingHelper {
.textTheme
.bodyMedium!
.copyWith(
color: ColorsManager
.textPrimaryColor,
fontWeight:
FontWeight.w400,
color: ColorsManager.textPrimaryColor,
fontWeight: FontWeight.w400,
fontSize: 14),
),
Text('Cloud',
@ -173,12 +162,8 @@ class SettingHelper {
.textTheme
.bodyMedium!
.copyWith(
color:
ColorsManager
.textGray,
fontWeight:
FontWeight
.w400,
color: ColorsManager.textGray,
fontWeight: FontWeight.w400,
fontSize: 14)),
],
),
@ -191,26 +176,20 @@ class SettingHelper {
children: [
Container(
padding: const EdgeInsets.only(
top: 10,
left: 10,
right: 10,
bottom: 10),
top: 10, left: 10, right: 10, bottom: 10),
child: Column(
children: [
InkWell(
onTap: () {
BlocProvider.of<SettingBloc>(
context)
.add(FetchIcons(
BlocProvider.of<SettingBloc>(context).add(
FetchIcons(
expanded: !context
.read<
SettingBloc>()
.read<SettingBloc>()
.isExpanded));
},
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
MainAxisAlignment.spaceBetween,
children: [
Text(
'Icons',
@ -218,18 +197,14 @@ class SettingHelper {
.textTheme
.bodyMedium!
.copyWith(
color: ColorsManager
.textPrimaryColor,
fontWeight:
FontWeight
.w400,
color:
ColorsManager.textPrimaryColor,
fontWeight: FontWeight.w400,
fontSize: 14),
),
const Icon(
Icons
.arrow_forward_ios_outlined,
color: ColorsManager
.textGray,
Icons.arrow_forward_ios_outlined,
color: ColorsManager.textGray,
size: 15,
)
],
@ -245,9 +220,7 @@ class SettingHelper {
height: 5,
),
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Show on devices page',
@ -255,21 +228,17 @@ class SettingHelper {
.textTheme
.bodyMedium!
.copyWith(
color: ColorsManager
.textPrimaryColor,
fontWeight:
FontWeight.w400,
color: ColorsManager.textPrimaryColor,
fontWeight: FontWeight.w400,
fontSize: 14),
),
Row(
mainAxisAlignment:
MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
height: 30,
width: 1,
color: ColorsManager
.graysColor,
color: ColorsManager.graysColor,
),
Transform.scale(
scale: .8,
@ -293,9 +262,7 @@ class SettingHelper {
height: 5,
),
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Executed by',
@ -303,10 +270,8 @@ class SettingHelper {
.textTheme
.bodyMedium!
.copyWith(
color: ColorsManager
.textPrimaryColor,
fontWeight:
FontWeight.w400,
color: ColorsManager.textPrimaryColor,
fontWeight: FontWeight.w400,
fontSize: 14),
),
Text('Cloud',
@ -314,12 +279,8 @@ class SettingHelper {
.textTheme
.bodyMedium!
.copyWith(
color:
ColorsManager
.textGray,
fontWeight:
FontWeight
.w400,
color: ColorsManager.textGray,
fontWeight: FontWeight.w400,
fontSize: 14)),
],
),
@ -328,14 +289,12 @@ class SettingHelper {
],
),
),
if (context.read<SettingBloc>().isExpanded &&
!isAutomation)
if (context.read<SettingBloc>().isExpanded && !isAutomation)
SizedBox(
width: 400,
height: 150,
child: state is LoadingState
? const Center(
child: CircularProgressIndicator())
child: settingState is LoadingState
? const Center(child: CircularProgressIndicator())
: GridView.builder(
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
@ -352,8 +311,7 @@ class SettingHelper {
height: 35,
child: InkWell(
onTap: () {
BlocProvider.of<SettingBloc>(
context)
BlocProvider.of<SettingBloc>(context)
.add(SelectIcon(
iconId: iconModel.uuid,
));
@ -362,16 +320,13 @@ class SettingHelper {
child: SizedBox(
child: ClipOval(
child: Container(
padding:
const EdgeInsets.all(1),
padding: const EdgeInsets.all(1),
decoration: BoxDecoration(
border: Border.all(
color: selectedIcon ==
iconModel.uuid
color: selectedIcon == iconModel.uuid
? ColorsManager
.primaryColorWithOpacity
: Colors
.transparent,
: Colors.transparent,
width: 2,
),
shape: BoxShape.circle,
@ -386,12 +341,8 @@ class SettingHelper {
);
},
)),
if (context.read<SettingBloc>().isExpanded &&
isAutomation)
const SizedBox(
height: 350,
width: 400,
child: EffectivePeriodView())
if (context.read<SettingBloc>().isExpanded && isAutomation)
const SizedBox(height: 350, width: 400, child: EffectivePeriodView())
],
),
Container(
@ -415,35 +366,34 @@ class SettingHelper {
alignment: AlignmentDirectional.center,
child: Text(
'Cancel',
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: ColorsManager.textGray,
),
),
),
),
),
Container(
width: 1,
height: 50,
color: ColorsManager.greyColor),
Container(width: 1, height: 50, color: ColorsManager.greyColor),
Expanded(
child: InkWell(
onTap: () {
if (isAutomation) {
BlocProvider.of<RoutineBloc>(context).add(
EffectiveTimePeriodEvent(EffectiveTime(
start: effectPeriodState.customStartTime!,
end: effectPeriodState.customEndTime!,
loops: effectPeriodState.selectedDaysBinary)));
Navigator.of(context).pop();
} else {
Navigator.of(context).pop(selectedIcon);
}
},
child: Container(
alignment: AlignmentDirectional.center,
child: Text(
'Confirm',
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(
color: ColorsManager
.primaryColorWithOpacity,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: ColorsManager.primaryColorWithOpacity,
),
),
),
@ -456,7 +406,8 @@ class SettingHelper {
),
);
},
),
);
}),
),
);
},

View File

@ -182,7 +182,9 @@ class RoutineSearchAndButtons extends StatelessWidget {
width: 200,
child: Center(
child: DefaultButton(
onPressed: () {},
onPressed: () {
DiscardDialog.show(context);
},
borderRadius: 15,
elevation: 0,
borderColor: ColorsManager.greyColor,

View File

@ -26,9 +26,7 @@ class ThenContainer extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('THEN',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold)),
const Text('THEN', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
Wrap(
spacing: 8,
@ -37,16 +35,12 @@ class ThenContainer extends StatelessWidget {
state.thenItems.length,
(index) => GestureDetector(
onTap: () async {
if (state.thenItems[index]['deviceId'] ==
'delay') {
final result = await DelayHelper
.showDelayPickerDialog(
if (state.thenItems[index]['deviceId'] == 'delay') {
final result = await DelayHelper.showDelayPickerDialog(
context, state.thenItems[index]);
if (result != null) {
context
.read<RoutineBloc>()
.add(AddToThenContainer({
context.read<RoutineBloc>().add(AddToThenContainer({
...state.thenItems[index],
'imagePath': Assets.delay,
'title': 'Delay',
@ -55,37 +49,32 @@ class ThenContainer extends StatelessWidget {
return;
}
final result = await DeviceDialogHelper
.showDeviceDialog(
final result = await DeviceDialogHelper.showDeviceDialog(
context, state.thenItems[index]);
if (result != null) {
context.read<RoutineBloc>().add(
AddToThenContainer(
state.thenItems[index]));
context
.read<RoutineBloc>()
.add(AddToThenContainer(state.thenItems[index]));
} else if (!['AC', '1G', '2G', '3G']
.contains(state.thenItems[index]
['productType'])) {
context.read<RoutineBloc>().add(
AddToThenContainer(
state.thenItems[index]));
.contains(state.thenItems[index]['productType'])) {
context
.read<RoutineBloc>()
.add(AddToThenContainer(state.thenItems[index]));
}
},
child: DraggableCard(
imagePath: state.thenItems[index]
['imagePath'] ??
'',
title:
state.thenItems[index]['title'] ?? '',
imagePath: state.thenItems[index]['imagePath'] ?? '',
title: state.thenItems[index]['title'] ?? '',
deviceData: state.thenItems[index],
padding: const EdgeInsets.symmetric(
horizontal: 4, vertical: 8),
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
isFromThen: true,
isFromIf: false,
onRemove: () {
context.read<RoutineBloc>().add(
RemoveDragCard(
index: index, isFromThen: true));
context.read<RoutineBloc>().add(RemoveDragCard(
index: index,
isFromThen: true,
key: state.thenItems[index]['uniqueCustomId']));
},
),
))),
@ -140,8 +129,7 @@ class ThenContainer extends StatelessWidget {
}
if (mutableData['deviceId'] == 'delay') {
final result =
await DelayHelper.showDelayPickerDialog(context, mutableData);
final result = await DelayHelper.showDelayPickerDialog(context, mutableData);
if (result != null) {
context.read<RoutineBloc>().add(AddToThenContainer({
@ -153,13 +141,11 @@ class ThenContainer extends StatelessWidget {
return;
}
final result =
await DeviceDialogHelper.showDeviceDialog(context, mutableData);
final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData);
if (result != null) {
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
} else if (!['AC', '1G', '2G', '3G']
.contains(mutableData['productType'])) {
} else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) {
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
}
},