mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-17 02:25:16 +00:00
push dialog changes in values
This commit is contained in:
@ -315,6 +315,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
automationTempTasksList.clear();
|
automationTempTasksList.clear();
|
||||||
automationSelectedValues.clear();
|
automationSelectedValues.clear();
|
||||||
automationComparatorValues.clear();
|
automationComparatorValues.clear();
|
||||||
|
effectiveTime = null;
|
||||||
sceneType = CreateSceneEnum.none;
|
sceneType = CreateSceneEnum.none;
|
||||||
conditionRule = 'or';
|
conditionRule = 'or';
|
||||||
emit(const CreateSceneWithTasks(success: true));
|
emit(const CreateSceneWithTasks(success: true));
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/smart_scene_enable.dart';
|
||||||
|
|
||||||
|
part 'smart_scene_select_dart_event.dart';
|
||||||
|
part 'smart_scene_select_dart_state.dart';
|
||||||
|
|
||||||
|
class SmartSceneSelectBloc
|
||||||
|
extends Bloc<SmartSceneSelectEvent, SmartSceneSelectState> {
|
||||||
|
SmartSceneSelectBloc() : super(SmartSceneSelectInitial()) {
|
||||||
|
on<SmartSceneEnableEvent>(_onSmartSceneEnable);
|
||||||
|
on<SmartSceneClearEvent>(_smartSceneClear);
|
||||||
|
}
|
||||||
|
|
||||||
|
SmartSceneEnable? smartSceneEnable;
|
||||||
|
|
||||||
|
FutureOr<void> _onSmartSceneEnable(
|
||||||
|
SmartSceneEnableEvent event, Emitter<SmartSceneSelectState> emit) {
|
||||||
|
smartSceneEnable = event.smartSceneEnable;
|
||||||
|
emit(SmartSceneSelected(smartSceneEnable: smartSceneEnable!));
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _smartSceneClear(
|
||||||
|
SmartSceneClearEvent event, Emitter<SmartSceneSelectState> emit) {
|
||||||
|
smartSceneEnable = null;
|
||||||
|
emit(SmartSceneSelectInitial());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
part of 'smart_scene_select_dart_bloc.dart';
|
||||||
|
|
||||||
|
sealed class SmartSceneSelectEvent extends Equatable {
|
||||||
|
const SmartSceneSelectEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SmartSceneEnableEvent extends SmartSceneSelectEvent {
|
||||||
|
final SmartSceneEnable smartSceneEnable;
|
||||||
|
|
||||||
|
const SmartSceneEnableEvent(this.smartSceneEnable);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [smartSceneEnable];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SmartSceneClearEvent extends SmartSceneSelectEvent {
|
||||||
|
const SmartSceneClearEvent();
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
part of 'smart_scene_select_dart_bloc.dart';
|
||||||
|
|
||||||
|
sealed class SmartSceneSelectState extends Equatable {
|
||||||
|
const SmartSceneSelectState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class SmartSceneSelectInitial extends SmartSceneSelectState {}
|
||||||
|
|
||||||
|
class SmartSceneSelected extends SmartSceneSelectState {
|
||||||
|
final SmartSceneEnable smartSceneEnable;
|
||||||
|
|
||||||
|
const SmartSceneSelected({required this.smartSceneEnable});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [smartSceneEnable];
|
||||||
|
}
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
|
import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/create_automation_model.dart';
|
import 'package:syncrow_app/features/scene/model/create_automation_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/create_scene_model.dart';
|
import 'package:syncrow_app/features/scene/model/create_scene_model.dart';
|
||||||
@ -29,6 +30,7 @@ mixin SceneLogicHelper {
|
|||||||
required List<SceneStaticFunction> conditions,
|
required List<SceneStaticFunction> conditions,
|
||||||
}) {
|
}) {
|
||||||
final sceneBloc = context.read<CreateSceneBloc>();
|
final sceneBloc = context.read<CreateSceneBloc>();
|
||||||
|
final smartSceneBloc = context.read<SmartSceneSelectBloc>();
|
||||||
|
|
||||||
if (isAutomation) {
|
if (isAutomation) {
|
||||||
// Handle Automation Creation
|
// Handle Automation Creation
|
||||||
@ -89,7 +91,11 @@ mixin SceneLogicHelper {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
)..add(CreateSceneAction(
|
||||||
|
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||||
|
actionExecutor:
|
||||||
|
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||||
|
executorProperty: null)),
|
||||||
);
|
);
|
||||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||||
createSceneModel: null,
|
createSceneModel: null,
|
||||||
@ -140,7 +146,11 @@ mixin SceneLogicHelper {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
)..add(CreateSceneAction(
|
||||||
|
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||||
|
actionExecutor:
|
||||||
|
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||||
|
executorProperty: null)),
|
||||||
);
|
);
|
||||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||||
createSceneModel: createSceneModel,
|
createSceneModel: createSceneModel,
|
||||||
|
@ -81,7 +81,7 @@ class CreateSceneModel {
|
|||||||
class CreateSceneAction {
|
class CreateSceneAction {
|
||||||
String entityId;
|
String entityId;
|
||||||
String actionExecutor;
|
String actionExecutor;
|
||||||
CreateSceneExecutorProperty executorProperty;
|
CreateSceneExecutorProperty? executorProperty;
|
||||||
|
|
||||||
CreateSceneAction({
|
CreateSceneAction({
|
||||||
required this.entityId,
|
required this.entityId,
|
||||||
@ -105,7 +105,8 @@ class CreateSceneAction {
|
|||||||
return {
|
return {
|
||||||
'entityId': entityId,
|
'entityId': entityId,
|
||||||
'actionExecutor': actionExecutor,
|
'actionExecutor': actionExecutor,
|
||||||
'executorProperty': executorProperty.toMap(actionExecutor),
|
if (executorProperty != null)
|
||||||
|
'executorProperty': executorProperty?.toMap(actionExecutor),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
lib/features/scene/model/smart_scene_enable.dart
Normal file
23
lib/features/scene/model/smart_scene_enable.dart
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
class SmartSceneEnable {
|
||||||
|
final String entityId;
|
||||||
|
final String actionExecutor;
|
||||||
|
|
||||||
|
SmartSceneEnable({
|
||||||
|
required this.entityId,
|
||||||
|
required this.actionExecutor,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory SmartSceneEnable.fromJson(Map<String, dynamic> json) {
|
||||||
|
return SmartSceneEnable(
|
||||||
|
entityId: json['entityId'],
|
||||||
|
actionExecutor: json['actionExecutor'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'entityId': entityId,
|
||||||
|
'actionExecutor': actionExecutor,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -65,32 +65,28 @@ class DeviceFunctionsView extends StatelessWidget
|
|||||||
],
|
],
|
||||||
leading: TextButton(
|
leading: TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// if (isAutomation) {
|
final automationSelectedValue =
|
||||||
final automationSelectedValue =
|
context.read<CreateSceneBloc>().automationSelectedValues;
|
||||||
context.read<CreateSceneBloc>().automationSelectedValues;
|
for (var element in device.functions) {
|
||||||
for (var element in device.functions) {
|
if (automationSelectedValue.containsKey(element.code)) {
|
||||||
if (automationSelectedValue.containsKey(element.code)) {
|
context.read<CreateSceneBloc>().add(RemoveTempTaskByIdEvent(
|
||||||
context.read<CreateSceneBloc>().add(RemoveTempTaskByIdEvent(
|
code: element.code!, isAutomation: true));
|
||||||
code: element.code!, isAutomation: true));
|
context.read<CreateSceneBloc>().add(RemoveFromSelectedValueById(
|
||||||
context.read<CreateSceneBloc>().add(
|
code: element.code!, isAutomation: true));
|
||||||
RemoveFromSelectedValueById(
|
|
||||||
code: element.code!, isAutomation: true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// } else {
|
}
|
||||||
final selectedValue =
|
final selectedValue =
|
||||||
context.read<CreateSceneBloc>().selectedValues;
|
context.read<CreateSceneBloc>().selectedValues;
|
||||||
for (var element in device.functions) {
|
for (var element in device.functions) {
|
||||||
if (selectedValue.containsKey(element.code)) {
|
if (selectedValue.containsKey(element.code)) {
|
||||||
context
|
context
|
||||||
.read<CreateSceneBloc>()
|
.read<CreateSceneBloc>()
|
||||||
.add(RemoveTempTaskByIdEvent(code: element.code!));
|
.add(RemoveTempTaskByIdEvent(code: element.code!));
|
||||||
context
|
context
|
||||||
.read<CreateSceneBloc>()
|
.read<CreateSceneBloc>()
|
||||||
.add(RemoveFromSelectedValueById(code: element.code!));
|
.add(RemoveFromSelectedValueById(code: element.code!));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
|
70
lib/features/scene/view/smart_automation_select_route.dart
Normal file
70
lib/features/scene/view/smart_automation_select_route.dart
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_enable_tab_run.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||||
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
|
import 'package:syncrow_app/navigation/navigate_to_route.dart';
|
||||||
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class SmartAutomationSelectView extends StatelessWidget {
|
||||||
|
const SmartAutomationSelectView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return DefaultScaffold(
|
||||||
|
title: "Select Smart Scene",
|
||||||
|
padding: const EdgeInsets.only(top: 24),
|
||||||
|
leading: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
navigateToRoute(context, Routes.sceneTasksRoute);
|
||||||
|
},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.arrow_back_ios,
|
||||||
|
)),
|
||||||
|
height: 260,
|
||||||
|
child: DefaultContainer(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
SceneListTile(
|
||||||
|
assetPath: Assets.handClickIcon,
|
||||||
|
titleString: "Tap To Run",
|
||||||
|
subtitleString: '',
|
||||||
|
trailingWidget: const Icon(
|
||||||
|
Icons.arrow_forward_ios_rounded,
|
||||||
|
color: ColorsManager.greyColor,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
context.customBottomSheet(
|
||||||
|
child: const SmartEnableTabRun(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const Divider(
|
||||||
|
color: ColorsManager.dividerColor,
|
||||||
|
),
|
||||||
|
SceneListTile(
|
||||||
|
assetPath: Assets.refreshIcon,
|
||||||
|
titleString: "Automation",
|
||||||
|
subtitleString: '',
|
||||||
|
trailingWidget: const Icon(
|
||||||
|
Icons.arrow_forward_ios_rounded,
|
||||||
|
color: ColorsManager.greyColor,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
context.customBottomSheet(
|
||||||
|
child: const SmartEnableAutomation(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -67,7 +67,9 @@ class CustomBottomSheetWidget extends StatelessWidget {
|
|||||||
size: 16,
|
size: 16,
|
||||||
color: ColorsManager.greyColor,
|
color: ColorsManager.greyColor,
|
||||||
),
|
),
|
||||||
onPressed: () {},
|
onPressed: () {
|
||||||
|
Navigator.pushNamed(context, Routes.smartAutomationSelectRoute);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
SceneListTile(
|
SceneListTile(
|
||||||
assetPath: Assets.delay,
|
assetPath: Assets.delay,
|
||||||
|
@ -0,0 +1,260 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/smart_scene_enable.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class SmartSceneSelectAutomationList extends StatefulWidget {
|
||||||
|
const SmartSceneSelectAutomationList({
|
||||||
|
super.key,
|
||||||
|
required this.automationList,
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<ScenesModel> automationList;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SmartSceneSelectAutomationList> createState() =>
|
||||||
|
_SmartSceneSelectAutomationListState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SmartSceneSelectAutomationListState
|
||||||
|
extends State<SmartSceneSelectAutomationList> {
|
||||||
|
final List<Color> colorList = _generateDarkColors(100);
|
||||||
|
|
||||||
|
static List<Color> _generateDarkColors(int count) {
|
||||||
|
final random = Random();
|
||||||
|
final colors = <Color>[];
|
||||||
|
|
||||||
|
while (colors.length < count) {
|
||||||
|
final color =
|
||||||
|
Color((random.nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
|
||||||
|
if (_isDark(color)) {
|
||||||
|
colors.add(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool _isDark(Color color) {
|
||||||
|
final brightness =
|
||||||
|
((color.red * 299) + (color.green * 587) + (color.blue * 114)) / 1000;
|
||||||
|
return brightness < 128;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
|
child: BodyMedium(
|
||||||
|
text: 'Automation',
|
||||||
|
style: context.bodyMedium.copyWith(
|
||||||
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
|
fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(
|
||||||
|
color: ColorsManager.dividerColor,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: BlocBuilder<SmartSceneSelectBloc, SmartSceneSelectState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
final smartSceneEnable = ((state is SmartSceneSelected))
|
||||||
|
? state.smartSceneEnable
|
||||||
|
: context.read<SmartSceneSelectBloc>().smartSceneEnable;
|
||||||
|
|
||||||
|
return ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemCount: widget.automationList.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final automation = widget.automationList[index];
|
||||||
|
final isSelected =
|
||||||
|
smartSceneEnable?.entityId == automation.id;
|
||||||
|
final descriptionSelected = isSelected
|
||||||
|
? (smartSceneEnable?.actionExecutor == 'rule_enable'
|
||||||
|
? 'Enable'
|
||||||
|
: 'Disable')
|
||||||
|
: automation.status == 'enable'
|
||||||
|
? 'Enable'
|
||||||
|
: 'Disable';
|
||||||
|
|
||||||
|
return SceneListTile(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
leadingWidget: CircleAvatar(
|
||||||
|
backgroundColor: colorList[index % colorList.length],
|
||||||
|
radius: 15,
|
||||||
|
child: Text(
|
||||||
|
index.toString(),
|
||||||
|
style: context.bodyMedium.copyWith(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
titleString: automation.name,
|
||||||
|
trailingWidget: TextButton.icon(
|
||||||
|
iconAlignment: IconAlignment.end,
|
||||||
|
onPressed: () {
|
||||||
|
context.customAlertDialog(
|
||||||
|
alertBody: EnableDisableAutomationDialog(
|
||||||
|
automationId: automation.id,
|
||||||
|
descriptionSelected: descriptionSelected,
|
||||||
|
),
|
||||||
|
title: automation.name,
|
||||||
|
onConfirm: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
onDismiss: () {
|
||||||
|
context
|
||||||
|
.read<SmartSceneSelectBloc>()
|
||||||
|
.add(const SmartSceneClearEvent());
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
label: BodyMedium(
|
||||||
|
text: _capitalizeFirst(descriptionSelected),
|
||||||
|
style: context.bodyMedium
|
||||||
|
.copyWith(color: ColorsManager.greyColor),
|
||||||
|
),
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.arrow_forward_ios_rounded,
|
||||||
|
color: ColorsManager.greyColor,
|
||||||
|
size: 14,
|
||||||
|
),
|
||||||
|
style: const ButtonStyle(
|
||||||
|
padding: WidgetStatePropertyAll(EdgeInsets.zero),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
context.customAlertDialog(
|
||||||
|
alertBody: EnableDisableAutomationDialog(
|
||||||
|
automationId: automation.id,
|
||||||
|
descriptionSelected: descriptionSelected,
|
||||||
|
),
|
||||||
|
title: automation.name,
|
||||||
|
onConfirm: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
onDismiss: () {
|
||||||
|
context
|
||||||
|
.read<SmartSceneSelectBloc>()
|
||||||
|
.add(const SmartSceneClearEvent());
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _capitalizeFirst(String description) {
|
||||||
|
if (description.isEmpty) return description;
|
||||||
|
return '${description[0].toUpperCase()}${description.substring(1)}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EnableDisableAutomationDialog extends StatefulWidget {
|
||||||
|
const EnableDisableAutomationDialog({
|
||||||
|
super.key,
|
||||||
|
required this.automationId,
|
||||||
|
required this.descriptionSelected,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String automationId;
|
||||||
|
final String descriptionSelected;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<EnableDisableAutomationDialog> createState() =>
|
||||||
|
_EnableDisableAutomationDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EnableDisableAutomationDialogState
|
||||||
|
extends State<EnableDisableAutomationDialog> {
|
||||||
|
String? groupValue;
|
||||||
|
final List<SceneOperationalValue> values = [
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPower,
|
||||||
|
description: 'Enable',
|
||||||
|
value: 'rule_enable',
|
||||||
|
),
|
||||||
|
SceneOperationalValue(
|
||||||
|
icon: Assets.assetsAcPowerOFF,
|
||||||
|
description: 'Disable',
|
||||||
|
value: 'rule_disable',
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
groupValue =
|
||||||
|
widget.descriptionSelected == 'Enable' ? 'rule_enable' : 'rule_disable';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<SmartSceneSelectBloc, SmartSceneSelectState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
...values.map(
|
||||||
|
(operation) => SceneListTile(
|
||||||
|
iconsSize: 25,
|
||||||
|
minLeadingWidth: 15,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
|
assetPath: operation.icon,
|
||||||
|
assetHeaderValue: operation.iconValue,
|
||||||
|
titleString: operation.description.toString(),
|
||||||
|
textAlign: TextAlign.start,
|
||||||
|
trailingWidget: Radio(
|
||||||
|
value: operation.value,
|
||||||
|
groupValue: groupValue,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
groupValue = value;
|
||||||
|
});
|
||||||
|
context
|
||||||
|
.read<SmartSceneSelectBloc>()
|
||||||
|
.add(SmartSceneEnableEvent(
|
||||||
|
SmartSceneEnable(
|
||||||
|
entityId: widget.automationId,
|
||||||
|
actionExecutor: value!,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
groupValue = operation.value;
|
||||||
|
});
|
||||||
|
context
|
||||||
|
.read<SmartSceneSelectBloc>()
|
||||||
|
.add(SmartSceneEnableEvent(
|
||||||
|
SmartSceneEnable(
|
||||||
|
entityId: widget.automationId,
|
||||||
|
actionExecutor: operation.value,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
|
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_automation_list.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
|
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
|
||||||
|
class SmartEnableAutomation extends StatelessWidget {
|
||||||
|
const SmartEnableAutomation({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return DefaultContainer(
|
||||||
|
height: context.height * 0.5,
|
||||||
|
width: double.infinity,
|
||||||
|
child: BlocBuilder<SceneBloc, SceneState>(
|
||||||
|
bloc: context.read<SceneBloc>()
|
||||||
|
..add(
|
||||||
|
LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '')),
|
||||||
|
builder: (context, state) {
|
||||||
|
if (state is SceneLoading) {
|
||||||
|
return const Align(
|
||||||
|
alignment: Alignment.topCenter,
|
||||||
|
child: LinearProgressIndicator());
|
||||||
|
}
|
||||||
|
if (state is SceneLoaded) {
|
||||||
|
return SmartSceneSelectAutomationList(
|
||||||
|
automationList: state.automationList);
|
||||||
|
}
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_tab_run_list.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
|
||||||
|
class SmartEnableTabRun extends StatelessWidget {
|
||||||
|
const SmartEnableTabRun({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return DefaultContainer(
|
||||||
|
height: context.height * 0.5,
|
||||||
|
width: double.infinity,
|
||||||
|
child: BlocBuilder<SceneBloc, SceneState>(
|
||||||
|
bloc: context.read<SceneBloc>()
|
||||||
|
..add(LoadScenes(HomeCubit.getInstance().selectedSpace?.id ?? '')),
|
||||||
|
builder: (context, state) {
|
||||||
|
if (state is SceneLoading) {
|
||||||
|
return const Align(
|
||||||
|
alignment: Alignment.topCenter,
|
||||||
|
child: LinearProgressIndicator());
|
||||||
|
}
|
||||||
|
if (state is SceneLoaded) {
|
||||||
|
return SmartSceneSelectTabToRunList(scenes: state.scenes);
|
||||||
|
}
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,92 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/smart_scene_enable.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class SmartSceneSelectTabToRunList extends StatefulWidget {
|
||||||
|
const SmartSceneSelectTabToRunList({
|
||||||
|
super.key,
|
||||||
|
required this.scenes,
|
||||||
|
});
|
||||||
|
final List<ScenesModel> scenes;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SmartSceneSelectTabToRunList> createState() =>
|
||||||
|
_SmartSceneSelectTabToRunListState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SmartSceneSelectTabToRunListState
|
||||||
|
extends State<SmartSceneSelectTabToRunList> {
|
||||||
|
String groupValue = '';
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
|
child: BodyMedium(
|
||||||
|
text: 'Tab To Run',
|
||||||
|
style: context.bodyMedium.copyWith(
|
||||||
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
|
fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(
|
||||||
|
color: ColorsManager.dividerColor,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemCount: widget.scenes.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final scene = widget.scenes[index];
|
||||||
|
return SceneListTile(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
leadingWidget: Image.asset(
|
||||||
|
height: 32,
|
||||||
|
width: 32,
|
||||||
|
Assets.assetsIconsLogo,
|
||||||
|
fit: BoxFit.fill,
|
||||||
|
),
|
||||||
|
titleString: scene.name,
|
||||||
|
trailingWidget: Radio(
|
||||||
|
value: scene.id,
|
||||||
|
groupValue: groupValue,
|
||||||
|
onChanged: (String? value) {
|
||||||
|
if (value != null) {
|
||||||
|
setState(() {
|
||||||
|
groupValue = value;
|
||||||
|
});
|
||||||
|
context
|
||||||
|
.read<SmartSceneSelectBloc>()
|
||||||
|
.add(SmartSceneEnableEvent(SmartSceneEnable(
|
||||||
|
entityId: scene.id,
|
||||||
|
actionExecutor: 'rule_enable',
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
groupValue = scene.id;
|
||||||
|
});
|
||||||
|
context
|
||||||
|
.read<SmartSceneSelectBloc>()
|
||||||
|
.add(SmartSceneEnableEvent(SmartSceneEnable(
|
||||||
|
entityId: scene.id,
|
||||||
|
actionExecutor: 'rule_enable',
|
||||||
|
)));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@ class DefaultScaffold extends StatelessWidget {
|
|||||||
this.padding,
|
this.padding,
|
||||||
this.leading,
|
this.leading,
|
||||||
this.leadingWidth,
|
this.leadingWidth,
|
||||||
|
this.height,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
@ -27,6 +28,7 @@ class DefaultScaffold extends StatelessWidget {
|
|||||||
final EdgeInsetsGeometry? padding;
|
final EdgeInsetsGeometry? padding;
|
||||||
final Widget? leading;
|
final Widget? leading;
|
||||||
final double? leadingWidth;
|
final double? leadingWidth;
|
||||||
|
final double? height;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AnnotatedRegion(
|
return AnnotatedRegion(
|
||||||
@ -54,8 +56,9 @@ class DefaultScaffold extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
body: Container(
|
body: Container(
|
||||||
width: MediaQuery.sizeOf(context).width,
|
width: MediaQuery.sizeOf(context).width,
|
||||||
height: MediaQuery.sizeOf(context).height,
|
height: height ?? MediaQuery.sizeOf(context).height,
|
||||||
padding: padding ?? const EdgeInsets.symmetric(horizontal: Constants.defaultPadding),
|
padding: padding ??
|
||||||
|
const EdgeInsets.symmetric(horizontal: Constants.defaultPadding),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
image: AssetImage(
|
image: AssetImage(
|
||||||
|
@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
|
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
|
||||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_bloc.dart';
|
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
@ -28,6 +29,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider(create: (context) => CreateSceneBloc()),
|
BlocProvider(create: (context) => CreateSceneBloc()),
|
||||||
BlocProvider(create: (context) => SceneBloc()),
|
BlocProvider(create: (context) => SceneBloc()),
|
||||||
BlocProvider(create: (context) => ProfileBloc()),
|
BlocProvider(create: (context) => ProfileBloc()),
|
||||||
|
BlocProvider(create: (context) => SmartSceneSelectBloc()),
|
||||||
|
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
|
@ -18,6 +18,7 @@ import 'package:syncrow_app/features/scene/view/scene_auto_settings.dart';
|
|||||||
import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart';
|
import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_rooms_tabbar.dart';
|
import 'package:syncrow_app/features/scene/view/scene_rooms_tabbar.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/view/smart_automation_select_route.dart';
|
||||||
import 'package:syncrow_app/features/splash/view/splash_view.dart';
|
import 'package:syncrow_app/features/splash/view/splash_view.dart';
|
||||||
import 'routing_constants.dart';
|
import 'routing_constants.dart';
|
||||||
|
|
||||||
@ -101,6 +102,12 @@ class Router {
|
|||||||
builder: (_) => const SceneAutoSettings(),
|
builder: (_) => const SceneAutoSettings(),
|
||||||
settings: settings,
|
settings: settings,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
case Routes.smartAutomationSelectRoute:
|
||||||
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => const SmartAutomationSelectView(),
|
||||||
|
settings: settings,
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
builder: (_) => Scaffold(
|
builder: (_) => Scaffold(
|
||||||
|
@ -20,6 +20,6 @@ class Routes {
|
|||||||
static const String sceneTasksRoute = '/scene-tasks';
|
static const String sceneTasksRoute = '/scene-tasks';
|
||||||
static const String sceneControlDevicesRoute = '/scene-control-devices';
|
static const String sceneControlDevicesRoute = '/scene-control-devices';
|
||||||
static const String deviceFunctionsRoute = '/device-functions';
|
static const String deviceFunctionsRoute = '/device-functions';
|
||||||
static const String sceneAutoSettingsRoute =
|
static const String sceneAutoSettingsRoute = '/scene-automation-settings';
|
||||||
'/scene-automation-settings';
|
static const String smartAutomationSelectRoute = '/smart-automation-select';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user