mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
con setting
This commit is contained in:
@ -10,6 +10,7 @@ import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
|
|||||||
import 'package:syncrow_app/features/scene/helper/scene_operations_data_helper.dart';
|
import 'package:syncrow_app/features/scene/helper/scene_operations_data_helper.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';
|
||||||
|
import 'package:syncrow_app/features/scene/model/icon_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
|
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
|
||||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||||
import 'package:syncrow_app/services/api/scene_api.dart';
|
import 'package:syncrow_app/services/api/scene_api.dart';
|
||||||
@ -36,6 +37,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
on<SelectConditionEvent>(_selectConditionRule);
|
on<SelectConditionEvent>(_selectConditionRule);
|
||||||
on<SceneTypeEvent>(_sceneTypeEvent);
|
on<SceneTypeEvent>(_sceneTypeEvent);
|
||||||
on<EffectiveTimePeriodEvent>(_onEffectiveTimeEvent);
|
on<EffectiveTimePeriodEvent>(_onEffectiveTimeEvent);
|
||||||
|
on<SceneIconEvent>(_fetchIconScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateSceneEnum sceneType = CreateSceneEnum.none;
|
CreateSceneEnum sceneType = CreateSceneEnum.none;
|
||||||
@ -53,7 +55,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
String conditionRule = 'or';
|
String conditionRule = 'or';
|
||||||
EffectiveTime? effectiveTime;
|
EffectiveTime? effectiveTime;
|
||||||
|
|
||||||
FutureOr<void> _onAddSceneTask(AddTaskEvent event, Emitter<CreateSceneState> emit) {
|
FutureOr<void> _onAddSceneTask(
|
||||||
|
AddTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
if (event.isAutomation == true) {
|
if (event.isAutomation == true) {
|
||||||
final copyList = List<SceneStaticFunction>.from(automationTempTasksList);
|
final copyList = List<SceneStaticFunction>.from(automationTempTasksList);
|
||||||
@ -88,7 +91,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addToTempTaskList(TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
void addToTempTaskList(
|
||||||
|
TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
|
|
||||||
@ -173,7 +177,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addToTempAutomationTaskList(TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
void addToTempAutomationTaskList(
|
||||||
|
TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
for (var element in automationTempTasksList) {
|
for (var element in automationTempTasksList) {
|
||||||
@ -195,8 +200,10 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
],
|
],
|
||||||
comparator: automationComparatorValues[element.code],
|
comparator: automationComparatorValues[element.code],
|
||||||
);
|
);
|
||||||
automationTempTasksList[automationTempTasksList.indexOf(element)] = updatedElement;
|
automationTempTasksList[automationTempTasksList.indexOf(element)] =
|
||||||
automationSelectedValues[updatedElement.code] = event.deviceControlModel.value;
|
updatedElement;
|
||||||
|
automationSelectedValues[updatedElement.code] =
|
||||||
|
event.deviceControlModel.value;
|
||||||
updated = true;
|
updated = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -216,10 +223,12 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
icon: '',
|
icon: '',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
comparator: automationComparatorValues[event.deviceControlModel.code] ?? '==',
|
comparator:
|
||||||
|
automationComparatorValues[event.deviceControlModel.code] ?? '==',
|
||||||
);
|
);
|
||||||
automationTempTasksList.add(newElement);
|
automationTempTasksList.add(newElement);
|
||||||
automationSelectedValues[newElement.code] = event.deviceControlModel.value;
|
automationSelectedValues[newElement.code] =
|
||||||
|
event.deviceControlModel.value;
|
||||||
}
|
}
|
||||||
emit(AddSceneTask(
|
emit(AddSceneTask(
|
||||||
tasksList: tasksList,
|
tasksList: tasksList,
|
||||||
@ -228,7 +237,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _selectedValue(SelectedValueEvent event, Emitter<CreateSceneState> emit) {
|
FutureOr<void> _selectedValue(
|
||||||
|
SelectedValueEvent event, Emitter<CreateSceneState> emit) {
|
||||||
if (event.isAutomation == true) {
|
if (event.isAutomation == true) {
|
||||||
automationSelectedValues[event.code] = event.value;
|
automationSelectedValues[event.code] = event.value;
|
||||||
automationComparatorValues[event.code] = event.comparator ?? '==';
|
automationComparatorValues[event.code] = event.comparator ?? '==';
|
||||||
@ -265,7 +275,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _removeTaskById(RemoveTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
FutureOr<void> _removeTaskById(
|
||||||
|
RemoveTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
if (event.isAutomation == true) {
|
if (event.isAutomation == true) {
|
||||||
for (var element in automationTasksList) {
|
for (var element in automationTasksList) {
|
||||||
@ -338,7 +349,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
: await SceneApi.createScene(event.createSceneModel!);
|
: await SceneApi.createScene(event.createSceneModel!);
|
||||||
} else if (event.createAutomationModel != null) {
|
} else if (event.createAutomationModel != null) {
|
||||||
response = event.updateScene
|
response = event.updateScene
|
||||||
? await SceneApi.updateAutomation(event.createAutomationModel!, event.sceneId)
|
? await SceneApi.updateAutomation(
|
||||||
|
event.createAutomationModel!, event.sceneId)
|
||||||
: await SceneApi.createAutomation(event.createAutomationModel!);
|
: await SceneApi.createAutomation(event.createAutomationModel!);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,12 +362,14 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
automationTempTasksList.clear();
|
automationTempTasksList.clear();
|
||||||
automationSelectedValues.clear();
|
automationSelectedValues.clear();
|
||||||
automationComparatorValues.clear();
|
automationComparatorValues.clear();
|
||||||
effectiveTime = EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
effectiveTime =
|
||||||
|
EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
||||||
sceneType = CreateSceneEnum.none;
|
sceneType = CreateSceneEnum.none;
|
||||||
conditionRule = 'or';
|
conditionRule = 'or';
|
||||||
emit(const CreateSceneWithTasks(success: true));
|
emit(const CreateSceneWithTasks(success: true));
|
||||||
CustomSnackBar.greenSnackBar(
|
CustomSnackBar.greenSnackBar(event.updateScene
|
||||||
event.updateScene ? 'Scene updated successfully' : 'Scene created successfully');
|
? 'Scene updated successfully'
|
||||||
|
: 'Scene created successfully');
|
||||||
} else {
|
} else {
|
||||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||||
}
|
}
|
||||||
@ -369,7 +383,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _clearTaskList(ClearTaskListEvent event, Emitter<CreateSceneState> emit) {
|
FutureOr<void> _clearTaskList(
|
||||||
|
ClearTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
automationTasksList.clear();
|
automationTasksList.clear();
|
||||||
tasksList.clear();
|
tasksList.clear();
|
||||||
@ -392,7 +407,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
automationTempTasksList.clear();
|
automationTempTasksList.clear();
|
||||||
automationSelectedValues.clear();
|
automationSelectedValues.clear();
|
||||||
automationComparatorValues.clear();
|
automationComparatorValues.clear();
|
||||||
effectiveTime = EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
effectiveTime =
|
||||||
|
EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
||||||
sceneType = CreateSceneEnum.none;
|
sceneType = CreateSceneEnum.none;
|
||||||
conditionRule = 'or';
|
conditionRule = 'or';
|
||||||
|
|
||||||
@ -401,10 +417,14 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
: await SceneApi.getSceneDetails(event.sceneId);
|
: await SceneApi.getSceneDetails(event.sceneId);
|
||||||
if (response.id.isNotEmpty) {
|
if (response.id.isNotEmpty) {
|
||||||
if (event.isAutomation) {
|
if (event.isAutomation) {
|
||||||
automationTasksList = List<SceneStaticFunction>.from(getTaskListFunctionsFromApi(
|
automationTasksList = List<SceneStaticFunction>.from(
|
||||||
actions: [], isAutomation: true, conditions: response.conditions));
|
getTaskListFunctionsFromApi(
|
||||||
|
actions: [],
|
||||||
|
isAutomation: true,
|
||||||
|
conditions: response.conditions));
|
||||||
tasksList = List<SceneStaticFunction>.from(
|
tasksList = List<SceneStaticFunction>.from(
|
||||||
getTaskListFunctionsFromApi(actions: response.actions, isAutomation: false));
|
getTaskListFunctionsFromApi(
|
||||||
|
actions: response.actions, isAutomation: false));
|
||||||
|
|
||||||
conditionRule = response.decisionExpr ?? conditionRule;
|
conditionRule = response.decisionExpr ?? conditionRule;
|
||||||
|
|
||||||
@ -417,11 +437,13 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
: EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
: EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
||||||
|
|
||||||
// Set the days directly from the API response
|
// Set the days directly from the API response
|
||||||
BlocProvider.of<EffectPeriodBloc>(NavigationService.navigatorKey.currentContext!)
|
BlocProvider.of<EffectPeriodBloc>(
|
||||||
|
NavigationService.navigatorKey.currentContext!)
|
||||||
.add(SetDays(response.effectiveTime?.loops ?? '1111111'));
|
.add(SetDays(response.effectiveTime?.loops ?? '1111111'));
|
||||||
|
|
||||||
// Set Custom Time and reset days first
|
// Set Custom Time and reset days first
|
||||||
BlocProvider.of<EffectPeriodBloc>(NavigationService.navigatorKey.currentContext!)
|
BlocProvider.of<EffectPeriodBloc>(
|
||||||
|
NavigationService.navigatorKey.currentContext!)
|
||||||
.add(SetCustomTime(effectiveTime!.start, effectiveTime!.end));
|
.add(SetCustomTime(effectiveTime!.start, effectiveTime!.end));
|
||||||
|
|
||||||
emit(AddSceneTask(
|
emit(AddSceneTask(
|
||||||
@ -431,7 +453,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
tasksList = List<SceneStaticFunction>.from(
|
tasksList = List<SceneStaticFunction>.from(
|
||||||
getTaskListFunctionsFromApi(actions: response.actions, isAutomation: false));
|
getTaskListFunctionsFromApi(
|
||||||
|
actions: response.actions, isAutomation: false));
|
||||||
emit(AddSceneTask(
|
emit(AddSceneTask(
|
||||||
tasksList: tasksList,
|
tasksList: tasksList,
|
||||||
condition: conditionRule,
|
condition: conditionRule,
|
||||||
@ -445,12 +468,35 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///scene/icon
|
||||||
|
///
|
||||||
|
List<IconModel> iconModel = [];
|
||||||
|
|
||||||
|
FutureOr<void> _fetchIconScene(
|
||||||
|
SceneIconEvent event, Emitter<CreateSceneState> emit) async {
|
||||||
|
emit(CreateSceneLoading());
|
||||||
|
try {
|
||||||
|
final response = await SceneApi.getIcon();
|
||||||
|
|
||||||
|
// Parse the response as a List of IconModel
|
||||||
|
iconModel = (response as List<dynamic>)
|
||||||
|
.map((iconJson) => IconModel.fromJson(iconJson as Map<String, dynamic>))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
emit(CreateSceneLoaded(iconModel)); // Ensure this state is defined to handle the loaded list
|
||||||
|
} catch (e) {
|
||||||
|
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
String _getDayFromIndex(int index) {
|
String _getDayFromIndex(int index) {
|
||||||
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||||
return days[index];
|
return days[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _clearTempTaskList(ClearTempTaskListEvent event, Emitter<CreateSceneState> emit) {
|
FutureOr<void> _clearTempTaskList(
|
||||||
|
ClearTempTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
if (event.isAutomation == true) {
|
if (event.isAutomation == true) {
|
||||||
automationTempTasksList.clear();
|
automationTempTasksList.clear();
|
||||||
@ -494,13 +540,17 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _deleteScene(DeleteSceneEvent event, Emitter<CreateSceneState> emit) async {
|
FutureOr<void> _deleteScene(
|
||||||
|
DeleteSceneEvent event, Emitter<CreateSceneState> emit) async {
|
||||||
emit(DeleteSceneLoading());
|
emit(DeleteSceneLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final response = sceneType.name == CreateSceneEnum.deviceStatusChanges.name
|
final response =
|
||||||
? await SceneApi.deleteAutomation(automationId: event.sceneId, unitUuid: event.unitUuid)
|
sceneType.name == CreateSceneEnum.deviceStatusChanges.name
|
||||||
: await SceneApi.deleteScene(sceneId: event.sceneId, unitUuid: event.unitUuid);
|
? await SceneApi.deleteAutomation(
|
||||||
|
automationId: event.sceneId, unitUuid: event.unitUuid)
|
||||||
|
: await SceneApi.deleteScene(
|
||||||
|
sceneId: event.sceneId, unitUuid: event.unitUuid);
|
||||||
if (response == true) {
|
if (response == true) {
|
||||||
emit(const DeleteSceneSuccess(true));
|
emit(const DeleteSceneSuccess(true));
|
||||||
} else {
|
} else {
|
||||||
@ -511,7 +561,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _updateTaskValue(UpdateTaskEvent event, Emitter<CreateSceneState> emit) {
|
FutureOr<void> _updateTaskValue(
|
||||||
|
UpdateTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
if (event.isAutomation == true) {
|
if (event.isAutomation == true) {
|
||||||
for (var i = 0; i < automationTasksList.length; i++) {
|
for (var i = 0; i < automationTasksList.length; i++) {
|
||||||
@ -547,7 +598,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _selectConditionRule(SelectConditionEvent event, Emitter<CreateSceneState> emit) {
|
FutureOr<void> _selectConditionRule(
|
||||||
|
SelectConditionEvent event, Emitter<CreateSceneState> emit) {
|
||||||
emit(CreateSceneInitial());
|
emit(CreateSceneInitial());
|
||||||
if (event.condition.contains('any')) {
|
if (event.condition.contains('any')) {
|
||||||
conditionRule = 'or';
|
conditionRule = 'or';
|
||||||
@ -562,7 +614,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _sceneTypeEvent(SceneTypeEvent event, Emitter<CreateSceneState> emit) {
|
FutureOr<void> _sceneTypeEvent(
|
||||||
|
SceneTypeEvent event, Emitter<CreateSceneState> emit) {
|
||||||
// emit(CreateSceneInitial());
|
// emit(CreateSceneInitial());
|
||||||
|
|
||||||
if (event.type == CreateSceneEnum.tabToRun) {
|
if (event.type == CreateSceneEnum.tabToRun) {
|
||||||
|
@ -183,3 +183,5 @@ class EffectiveTimePeriodEvent extends CreateSceneEvent {
|
|||||||
final EffectiveTime period;
|
final EffectiveTime period;
|
||||||
const EffectiveTimePeriodEvent(this.period);
|
const EffectiveTimePeriodEvent(this.period);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SceneIconEvent extends CreateSceneEvent {}
|
||||||
|
@ -84,3 +84,8 @@ class SceneTypeState extends CreateSceneState {
|
|||||||
final CreateSceneEnum type;
|
final CreateSceneEnum type;
|
||||||
const SceneTypeState(this.type);
|
const SceneTypeState(this.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CreateSceneLoaded extends CreateSceneState {
|
||||||
|
final List<IconModel> iconModels;
|
||||||
|
CreateSceneLoaded(this.iconModels);
|
||||||
|
}
|
||||||
|
39
lib/features/scene/model/icon_model.dart
Normal file
39
lib/features/scene/model/icon_model.dart
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
class IconModel {
|
||||||
|
final String uuid;
|
||||||
|
final DateTime createdAt;
|
||||||
|
final DateTime updatedAt;
|
||||||
|
final String iconBase64;
|
||||||
|
|
||||||
|
IconModel({
|
||||||
|
required this.uuid,
|
||||||
|
required this.createdAt,
|
||||||
|
required this.updatedAt,
|
||||||
|
required this.iconBase64,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Method to decode the icon from Base64 and return as Uint8List
|
||||||
|
Uint8List get iconBytes => base64Decode(iconBase64);
|
||||||
|
|
||||||
|
// Factory constructor to create an instance from JSON
|
||||||
|
factory IconModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return IconModel(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||||
|
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
||||||
|
iconBase64: json['icon'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to convert an instance back to JSON
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'uuid': uuid,
|
||||||
|
'createdAt': createdAt.toIso8601String(),
|
||||||
|
'updatedAt': updatedAt.toIso8601String(),
|
||||||
|
'icon': iconBase64,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -53,6 +53,7 @@ class SceneDetailsModel {
|
|||||||
"name": name,
|
"name": name,
|
||||||
"status": status,
|
"status": status,
|
||||||
"type": type,
|
"type": type,
|
||||||
|
|
||||||
"actions": List<dynamic>.from(actions.map((x) => x.toJson())),
|
"actions": List<dynamic>.from(actions.map((x) => x.toJson())),
|
||||||
"conditions": conditions != null
|
"conditions": conditions != null
|
||||||
? List<dynamic>.from(conditions!.map((x) => x.toJson()))
|
? List<dynamic>.from(conditions!.map((x) => x.toJson()))
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_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/enum/create_scene_enum.dart';
|
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart';
|
|
||||||
import 'package:syncrow_app/features/scene/widgets/effective_period_setting/effective_period_bottom_sheet.dart';
|
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_container.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/features/shared_widgets/default_scaffold.dart';
|
||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
class SceneAutoSettings extends StatelessWidget {
|
class SceneAutoSettings extends StatelessWidget {
|
||||||
@ -33,60 +35,305 @@ class SceneAutoSettings extends StatelessWidget {
|
|||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
Icons.arrow_back_ios,
|
Icons.arrow_back_ios,
|
||||||
)),
|
)),
|
||||||
child: SizedBox(
|
child: BlocProvider(
|
||||||
|
create: (BuildContext context) =>
|
||||||
|
CreateSceneBloc()..add(SceneIconEvent()),
|
||||||
|
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return SizedBox(
|
||||||
height: MediaQuery.sizeOf(context).height,
|
height: MediaQuery.sizeOf(context).height,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
DefaultContainer(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
child: Padding(
|
||||||
child: DefaultContainer(
|
padding: const EdgeInsets.only(
|
||||||
|
top: 10, left: 10, right: 10, bottom: 10),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(
|
InkWell(
|
||||||
height: 8,
|
onTap: () {
|
||||||
),
|
showDialog(
|
||||||
Visibility(
|
context: context,
|
||||||
visible: isAutomation,
|
builder: (context) {
|
||||||
child: SceneListTile(
|
return SecondDialog(
|
||||||
padding: const EdgeInsets.symmetric(
|
WidgetList: BlocBuilder<CreateSceneBloc,
|
||||||
horizontal: 16, vertical: 8),
|
CreateSceneState>(
|
||||||
titleString: "Effective Period",
|
builder: (context, state) {
|
||||||
trailingWidget:
|
if (state is CreateSceneLoading) {
|
||||||
const Icon(Icons.arrow_forward_ios_rounded),
|
return CircularProgressIndicator();
|
||||||
onPressed: () {
|
} else if (state is CreateSceneLoaded) {
|
||||||
context.customBottomSheet(
|
return Container(
|
||||||
child: const EffectPeriodBottomSheetContent(),
|
height: 100,
|
||||||
);
|
width: 100,
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount:
|
||||||
|
state.iconModels.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final iconModel =
|
||||||
|
state.iconModels[index];
|
||||||
|
return Image.memory(
|
||||||
|
iconModel.iconBytes);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
} else if (state is CreateSceneError) {
|
||||||
|
return Text(state.message);
|
||||||
|
} else {
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
Visibility(
|
cancelTab: () {
|
||||||
visible: sceneName.isNotEmpty && isAutomation,
|
Navigator.of(context).pop();
|
||||||
child: SizedBox(
|
},
|
||||||
width: context.width * 0.9,
|
confirmTab: (v) {
|
||||||
child: const Divider(
|
Navigator.of(context).pop();
|
||||||
color: ColorsManager.greyColor,
|
},
|
||||||
),
|
title: 'Icons',
|
||||||
),
|
onTapLabel1: (selected) {},
|
||||||
),
|
);
|
||||||
Visibility(
|
},
|
||||||
visible: sceneName.isNotEmpty,
|
);
|
||||||
child: DeleteBottomSheetContent(
|
},
|
||||||
isAutomation: isAutomation,
|
child: const Row(
|
||||||
sceneId: sceneId,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
BodyMedium(text: 'Icons'),
|
||||||
|
Icon(
|
||||||
|
Icons.arrow_forward_ios_outlined,
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
size: 15,
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 16,
|
height: 5,
|
||||||
),
|
),
|
||||||
],
|
const Divider(
|
||||||
|
color: ColorsManager.graysColor,
|
||||||
),
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const BodyMedium(text: 'Show on devices page'),
|
||||||
|
Container(
|
||||||
|
width: 100,
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
height: 30,
|
||||||
|
width: 1,
|
||||||
|
color: ColorsManager.graysColor,
|
||||||
|
),
|
||||||
|
Transform.scale(
|
||||||
|
scale: .8,
|
||||||
|
child: CupertinoSwitch(
|
||||||
|
value: true,
|
||||||
|
onChanged: (value) {},
|
||||||
|
applyTheme: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
const Divider(
|
||||||
|
color: ColorsManager.graysColor,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
const Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
//Cloud
|
||||||
|
BodyMedium(text: 'Executed by'),
|
||||||
|
Text('Cloud',
|
||||||
|
style: TextStyle(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
// Padding(
|
||||||
|
// padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
|
// child: DefaultContainer(
|
||||||
|
// child: Column(
|
||||||
|
// mainAxisSize: MainAxisSize.min,
|
||||||
|
// mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
// children: [
|
||||||
|
// const SizedBox(
|
||||||
|
// height: 8,
|
||||||
|
// ),
|
||||||
|
// Visibility(
|
||||||
|
// visible: isAutomation,
|
||||||
|
// child: SceneListTile(
|
||||||
|
// padding: const EdgeInsets.symmetric(
|
||||||
|
// horizontal: 16, vertical: 8),
|
||||||
|
// titleString: "Effective Period",
|
||||||
|
// trailingWidget:
|
||||||
|
// const Icon(Icons.arrow_forward_ios_rounded),
|
||||||
|
// onPressed: () {
|
||||||
|
// context.customBottomSheet(
|
||||||
|
// child: const EffectPeriodBottomSheetContent(),
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// Visibility(
|
||||||
|
// visible: sceneName.isNotEmpty && isAutomation,
|
||||||
|
// child: SizedBox(
|
||||||
|
// width: context.width * 0.9,
|
||||||
|
// child: const Divider(
|
||||||
|
// color: ColorsManager.greyColor,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// Visibility(
|
||||||
|
// visible: sceneName.isNotEmpty,
|
||||||
|
// child: DeleteBottomSheetContent(
|
||||||
|
// isAutomation: isAutomation,
|
||||||
|
// sceneId: sceneId,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// const SizedBox(
|
||||||
|
// height: 16,
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SecondDialog extends StatefulWidget {
|
||||||
|
final String title;
|
||||||
|
Widget WidgetList;
|
||||||
|
final Function(String)? onTapLabel1;
|
||||||
|
final Function()? cancelTab;
|
||||||
|
final Function(int selectedSecond)? confirmTab;
|
||||||
|
|
||||||
|
SecondDialog({
|
||||||
|
required this.WidgetList,
|
||||||
|
required this.title,
|
||||||
|
this.onTapLabel1,
|
||||||
|
required this.cancelTab,
|
||||||
|
required this.confirmTab,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SecondDialogState createState() => _SecondDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SecondDialogState extends State<SecondDialog> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
BodyLarge(
|
||||||
|
text: widget.title,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
fontColor: ColorsManager.primaryColor,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.only(left: 15, right: 15),
|
||||||
|
child: Divider(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(child: widget.WidgetList),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
right: BorderSide(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 0.5,
|
||||||
|
),
|
||||||
|
top: BorderSide(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
child: SizedBox(
|
||||||
|
child: InkWell(
|
||||||
|
onTap: widget.cancelTab,
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.all(15),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'Cancel',
|
||||||
|
style: TextStyle(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w400),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
left: BorderSide(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 0.5,
|
||||||
|
),
|
||||||
|
top: BorderSide(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () {},
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.all(15),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'Confirm',
|
||||||
|
style: TextStyle(
|
||||||
|
color: ColorsManager.primaryColor,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w400),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -128,6 +128,7 @@ abstract class ApiEndpoints {
|
|||||||
static const String getUnitScenes = '/scene/tap-to-run/{unitUuid}';
|
static const String getUnitScenes = '/scene/tap-to-run/{unitUuid}';
|
||||||
|
|
||||||
static const String getScene = '/scene/tap-to-run/details/{sceneId}';
|
static const String getScene = '/scene/tap-to-run/details/{sceneId}';
|
||||||
|
static const String getIconScene = '/scene/icon';
|
||||||
|
|
||||||
static const String getUnitAutomation = '/automation/{unitUuid}';
|
static const String getUnitAutomation = '/automation/{unitUuid}';
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
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';
|
||||||
import 'package:syncrow_app/features/scene/model/scene_details_model.dart';
|
import 'package:syncrow_app/features/scene/model/scene_details_model.dart';
|
||||||
@ -147,6 +149,22 @@ class SceneApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future getIcon() async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.get(
|
||||||
|
path: ApiEndpoints.getIconScene,
|
||||||
|
showServerMessage: false,
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
log(json);
|
||||||
|
return json;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//update Scene
|
//update Scene
|
||||||
static updateScene(CreateSceneModel createSceneModel, String sceneId) async {
|
static updateScene(CreateSceneModel createSceneModel, String sceneId) async {
|
||||||
try {
|
try {
|
||||||
|
@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for
|
|||||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||||
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||||
|
|
||||||
version: 1.0.5+31
|
version: 1.0.5+33
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=3.0.6 <4.0.0"
|
sdk: ">=3.0.6 <4.0.0"
|
||||||
|
Reference in New Issue
Block a user