mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
finished get scene details
This commit is contained in:
@ -3,6 +3,7 @@ import 'dart:async';
|
|||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/helper/scene_operations_data_helper.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_static_function.dart';
|
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
|
||||||
import 'package:syncrow_app/services/api/scene_api.dart';
|
import 'package:syncrow_app/services/api/scene_api.dart';
|
||||||
@ -10,13 +11,15 @@ import 'package:syncrow_app/services/api/scene_api.dart';
|
|||||||
part 'create_scene_event.dart';
|
part 'create_scene_event.dart';
|
||||||
part 'create_scene_state.dart';
|
part 'create_scene_state.dart';
|
||||||
|
|
||||||
class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState> {
|
class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||||
|
with SceneOperationsDataHelper {
|
||||||
CreateSceneBloc() : super(CreateSceneInitial()) {
|
CreateSceneBloc() : super(CreateSceneInitial()) {
|
||||||
on<CreateSceneWithTasksEvent>(_createSceneWithTasks);
|
on<CreateSceneWithTasksEvent>(_createSceneWithTasks);
|
||||||
on<AddTaskEvent>(_onAddSceneTask);
|
on<AddTaskEvent>(_onAddSceneTask);
|
||||||
on<SelectedValueEvent>(_selectedValue);
|
on<SelectedValueEvent>(_selectedValue);
|
||||||
on<RemoveTaskEvent>(_removeTaskById);
|
on<RemoveTaskEvent>(_removeTaskById);
|
||||||
on<ClearTaskListEvent>(_clearTaskList);
|
on<ClearTaskListEvent>(_clearTaskList);
|
||||||
|
on<FetchSceneTasks>(_fetchSceneTasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SceneStaticFunction> tasksList = [];
|
List<SceneStaticFunction> tasksList = [];
|
||||||
@ -31,6 +34,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState> {
|
|||||||
icon: event.icon,
|
icon: event.icon,
|
||||||
code: event.deviceControlModel.code ?? '',
|
code: event.deviceControlModel.code ?? '',
|
||||||
deviceId: event.deviceId,
|
deviceId: event.deviceId,
|
||||||
|
functionValue: event.deviceControlModel.value,
|
||||||
operationalValues: [
|
operationalValues: [
|
||||||
SceneOperationalValue(
|
SceneOperationalValue(
|
||||||
value: event.deviceControlModel.value,
|
value: event.deviceControlModel.value,
|
||||||
@ -84,4 +88,22 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState> {
|
|||||||
tasksList.clear();
|
tasksList.clear();
|
||||||
emit(AddSceneTask(tasksList: tasksList));
|
emit(AddSceneTask(tasksList: tasksList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _fetchSceneTasks(
|
||||||
|
FetchSceneTasks event, Emitter<CreateSceneState> emit) async {
|
||||||
|
emit(CreateSceneLoading());
|
||||||
|
|
||||||
|
try {
|
||||||
|
final response = await SceneApi.getSceneDetails(event.sceneId);
|
||||||
|
if (response.id.isNotEmpty) {
|
||||||
|
tasksList = getTaskListFunctionsFromApi(
|
||||||
|
actions: response.actions, deviceId: response.id);
|
||||||
|
emit(AddSceneTask(tasksList: tasksList));
|
||||||
|
} else {
|
||||||
|
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(CreateSceneError(message: e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,3 +59,11 @@ class ClearTaskListEvent extends CreateSceneEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FetchSceneTasks extends CreateSceneEvent {
|
||||||
|
final String sceneId;
|
||||||
|
const FetchSceneTasks({required this.sceneId});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
@ -3,7 +3,8 @@ import 'dart:async';
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scene_model.dart';
|
import 'package:syncrow_app/features/scene/model/create_scene_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
import 'package:syncrow_app/services/api/scene_api.dart';
|
import 'package:syncrow_app/services/api/scene_api.dart';
|
||||||
|
|
||||||
part 'scene_state.dart';
|
part 'scene_state.dart';
|
||||||
|
@ -12,7 +12,7 @@ class SceneInitial extends SceneState {}
|
|||||||
class SceneLoading extends SceneState {}
|
class SceneLoading extends SceneState {}
|
||||||
|
|
||||||
class SceneLoaded extends SceneState {
|
class SceneLoaded extends SceneState {
|
||||||
final List<SceneModel> scenes;
|
final List<ScenesModel> scenes;
|
||||||
final String? loadingSceneId;
|
final String? loadingSceneId;
|
||||||
|
|
||||||
const SceneLoaded(this.scenes, {this.loadingSceneId});
|
const SceneLoaded(this.scenes, {this.loadingSceneId});
|
||||||
|
@ -3,6 +3,8 @@ 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/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/scenes_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/utils/context_extension.dart';
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
94
lib/features/scene/model/scene_details_model.dart
Normal file
94
lib/features/scene/model/scene_details_model.dart
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class SceneDetailsModel {
|
||||||
|
final String id;
|
||||||
|
final String name;
|
||||||
|
final String status;
|
||||||
|
final String type;
|
||||||
|
final List<Action> actions;
|
||||||
|
|
||||||
|
SceneDetailsModel({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.status,
|
||||||
|
required this.type,
|
||||||
|
required this.actions,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory SceneDetailsModel.fromRawJson(String str) =>
|
||||||
|
SceneDetailsModel.fromJson(json.decode(str));
|
||||||
|
|
||||||
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
|
factory SceneDetailsModel.fromJson(Map<String, dynamic> json) =>
|
||||||
|
SceneDetailsModel(
|
||||||
|
id: json["id"],
|
||||||
|
name: json["name"],
|
||||||
|
status: json["status"],
|
||||||
|
type: json["type"],
|
||||||
|
actions:
|
||||||
|
List<Action>.from(json["actions"].map((x) => Action.fromJson(x))),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"id": id,
|
||||||
|
"name": name,
|
||||||
|
"status": status,
|
||||||
|
"type": type,
|
||||||
|
"actions": List<dynamic>.from(actions.map((x) => x.toJson())),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class Action {
|
||||||
|
final String actionExecutor;
|
||||||
|
final String entityId;
|
||||||
|
final ExecutorProperty executorProperty;
|
||||||
|
|
||||||
|
Action({
|
||||||
|
required this.actionExecutor,
|
||||||
|
required this.entityId,
|
||||||
|
required this.executorProperty,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Action.fromRawJson(String str) => Action.fromJson(json.decode(str));
|
||||||
|
|
||||||
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
|
factory Action.fromJson(Map<String, dynamic> json) => Action(
|
||||||
|
actionExecutor: json["actionExecutor"],
|
||||||
|
entityId: json["entityId"],
|
||||||
|
executorProperty: ExecutorProperty.fromJson(json["executorProperty"]),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"actionExecutor": actionExecutor,
|
||||||
|
"entityId": entityId,
|
||||||
|
"executorProperty": executorProperty.toJson(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExecutorProperty {
|
||||||
|
final String functionCode;
|
||||||
|
final dynamic functionValue;
|
||||||
|
|
||||||
|
ExecutorProperty({
|
||||||
|
required this.functionCode,
|
||||||
|
required this.functionValue,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory ExecutorProperty.fromRawJson(String str) =>
|
||||||
|
ExecutorProperty.fromJson(json.decode(str));
|
||||||
|
|
||||||
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
|
factory ExecutorProperty.fromJson(Map<String, dynamic> json) =>
|
||||||
|
ExecutorProperty(
|
||||||
|
functionCode: json["functionCode"],
|
||||||
|
functionValue: json["functionValue"],
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"functionCode": functionCode,
|
||||||
|
"functionValue": functionValue,
|
||||||
|
};
|
||||||
|
}
|
12
lib/features/scene/model/scene_settings_route_arguments.dart
Normal file
12
lib/features/scene/model/scene_settings_route_arguments.dart
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/// helper class for scene settings push route
|
||||||
|
class SceneSettingsRouteArguments {
|
||||||
|
final String sceneId;
|
||||||
|
final String sceneName;
|
||||||
|
final String sceneType;
|
||||||
|
|
||||||
|
SceneSettingsRouteArguments({
|
||||||
|
required this.sceneId,
|
||||||
|
required this.sceneName,
|
||||||
|
required this.sceneType,
|
||||||
|
});
|
||||||
|
}
|
@ -11,6 +11,8 @@ class SceneStaticFunction {
|
|||||||
final String deviceId;
|
final String deviceId;
|
||||||
final String operationName;
|
final String operationName;
|
||||||
final String uniqueCustomId;
|
final String uniqueCustomId;
|
||||||
|
final dynamic functionValue;
|
||||||
|
final String? deviceIcon;
|
||||||
|
|
||||||
SceneStaticFunction({
|
SceneStaticFunction({
|
||||||
required this.icon,
|
required this.icon,
|
||||||
@ -19,6 +21,8 @@ class SceneStaticFunction {
|
|||||||
required this.operationalValues,
|
required this.operationalValues,
|
||||||
required this.deviceId,
|
required this.deviceId,
|
||||||
required this.operationName,
|
required this.operationName,
|
||||||
|
required this.functionValue,
|
||||||
|
this.deviceIcon,
|
||||||
}) : uniqueCustomId = const Uuid().v4();
|
}) : uniqueCustomId = const Uuid().v4();
|
||||||
|
|
||||||
SceneStaticFunction copyWith({
|
SceneStaticFunction copyWith({
|
||||||
@ -28,6 +32,8 @@ class SceneStaticFunction {
|
|||||||
List<SceneOperationalValue>? operationalValues,
|
List<SceneOperationalValue>? operationalValues,
|
||||||
String? deviceId,
|
String? deviceId,
|
||||||
String? operationName,
|
String? operationName,
|
||||||
|
dynamic functionValue,
|
||||||
|
String? deviceIcon,
|
||||||
}) {
|
}) {
|
||||||
return SceneStaticFunction(
|
return SceneStaticFunction(
|
||||||
icon: icon ?? this.icon,
|
icon: icon ?? this.icon,
|
||||||
@ -36,6 +42,8 @@ class SceneStaticFunction {
|
|||||||
operationalValues: operationalValues ?? this.operationalValues,
|
operationalValues: operationalValues ?? this.operationalValues,
|
||||||
deviceId: deviceId ?? this.deviceId,
|
deviceId: deviceId ?? this.deviceId,
|
||||||
operationName: operationName ?? this.operationName,
|
operationName: operationName ?? this.operationName,
|
||||||
|
functionValue: functionValue ?? this.functionValue,
|
||||||
|
deviceIcon: deviceIcon ?? this.deviceIcon,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +54,9 @@ class SceneStaticFunction {
|
|||||||
'code': code,
|
'code': code,
|
||||||
'operationalValues': operationalValues.map((x) => x.toMap()).toList(),
|
'operationalValues': operationalValues.map((x) => x.toMap()).toList(),
|
||||||
'deviceId': deviceId,
|
'deviceId': deviceId,
|
||||||
'operationName': operationName
|
'operationName': operationName,
|
||||||
|
'functionValue': functionValue,
|
||||||
|
'deviceIcon': deviceIcon
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +70,8 @@ class SceneStaticFunction {
|
|||||||
),
|
),
|
||||||
deviceId: map['deviceId'] ?? '',
|
deviceId: map['deviceId'] ?? '',
|
||||||
operationName: map['operationName'] ?? '',
|
operationName: map['operationName'] ?? '',
|
||||||
|
functionValue: map['functionValue'] ?? '',
|
||||||
|
deviceIcon: map['deviceIcon'] ?? '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +82,7 @@ class SceneStaticFunction {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'SceneStaticFunction(icon: $icon, name: $deviceName, code: $code, operationalValues: $operationalValues, deviceId: $deviceId, operationName: $operationName)';
|
return 'SceneStaticFunction(icon: $icon, name: $deviceName, code: $code, operationalValues: $operationalValues, deviceId: $deviceId, operationName: $operationName, functionValue: $functionValue, deviceIcon: $deviceIcon)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -82,6 +94,8 @@ class SceneStaticFunction {
|
|||||||
other.deviceName == deviceName &&
|
other.deviceName == deviceName &&
|
||||||
other.code == code &&
|
other.code == code &&
|
||||||
other.operationName == operationName &&
|
other.operationName == operationName &&
|
||||||
|
other.functionValue == functionValue &&
|
||||||
|
other.deviceIcon == deviceIcon &&
|
||||||
listEquals(other.operationalValues, operationalValues) &&
|
listEquals(other.operationalValues, operationalValues) &&
|
||||||
other.deviceId == deviceId;
|
other.deviceId == deviceId;
|
||||||
}
|
}
|
||||||
@ -93,6 +107,8 @@ class SceneStaticFunction {
|
|||||||
code.hashCode ^
|
code.hashCode ^
|
||||||
deviceId.hashCode ^
|
deviceId.hashCode ^
|
||||||
operationName.hashCode ^
|
operationName.hashCode ^
|
||||||
|
functionValue.hashCode ^
|
||||||
|
deviceIcon.hashCode ^
|
||||||
operationalValues.hashCode;
|
operationalValues.hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
class SceneModel {
|
class ScenesModel {
|
||||||
final String id;
|
final String id;
|
||||||
final String name;
|
final String name;
|
||||||
final Status status;
|
final Status status;
|
||||||
final Type type;
|
final Type type;
|
||||||
|
|
||||||
SceneModel({
|
ScenesModel({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.status,
|
required this.status,
|
||||||
required this.type,
|
required this.type,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory SceneModel.fromRawJson(String str) =>
|
factory ScenesModel.fromRawJson(String str) =>
|
||||||
SceneModel.fromJson(json.decode(str));
|
ScenesModel.fromJson(json.decode(str));
|
||||||
|
|
||||||
String toRawJson() => json.encode(toJson());
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
factory SceneModel.fromJson(Map<String, dynamic> json) => SceneModel(
|
factory ScenesModel.fromJson(Map<String, dynamic> json) => ScenesModel(
|
||||||
id: json["id"],
|
id: json["id"],
|
||||||
name: json["name"],
|
name: json["name"],
|
||||||
status: statusValues.map[json["status"]]!,
|
status: statusValues.map[json["status"]]!,
|
@ -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/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/model/scene_settings_route_arguments.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.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';
|
||||||
@ -40,9 +41,13 @@ class CreateSceneView extends StatelessWidget {
|
|||||||
Navigator.pushNamed(
|
Navigator.pushNamed(
|
||||||
context,
|
context,
|
||||||
Routes.sceneTasksRoute,
|
Routes.sceneTasksRoute,
|
||||||
arguments: CreateSceneEnum.tabToRun,
|
arguments: SceneSettingsRouteArguments(
|
||||||
|
sceneType: CreateSceneEnum.tabToRun.name,
|
||||||
|
sceneId: '',
|
||||||
|
sceneName: '',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
context.read<CreateSceneBloc>().add(ClearTaskListEvent());
|
context.read<CreateSceneBloc>().add(const ClearTaskListEvent());
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
DefaultContainer(
|
DefaultContainer(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/create_scene_save_button.dart';
|
import 'package:syncrow_app/features/scene/widgets/create_scene_save_button.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/if_then_containers/if_container.dart';
|
import 'package:syncrow_app/features/scene/widgets/if_then_containers/if_container.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/if_then_containers/then_container.dart';
|
import 'package:syncrow_app/features/scene/widgets/if_then_containers/then_container.dart';
|
||||||
@ -14,8 +15,12 @@ class SceneTasksView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final sceneSettings = ModalRoute.of(context)!.settings.arguments
|
||||||
|
as SceneSettingsRouteArguments;
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: StringsManager.createScene,
|
title: sceneSettings.sceneName.isNotEmpty
|
||||||
|
? sceneSettings.sceneName
|
||||||
|
: StringsManager.createScene,
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
actions: [
|
actions: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
@ -33,21 +38,21 @@ class SceneTasksView extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
const SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
const SizedBox(
|
||||||
height: 24,
|
height: 24,
|
||||||
),
|
),
|
||||||
// IF
|
// IF
|
||||||
IFDefaultContainer(),
|
const IFDefaultContainer(),
|
||||||
SizedBox(
|
const SizedBox(
|
||||||
height: 8,
|
height: 8,
|
||||||
),
|
),
|
||||||
// THEN
|
// THEN
|
||||||
ThenDefaultContainer(),
|
ThenDefaultContainer(sceneId: sceneSettings.sceneId),
|
||||||
SizedBox(
|
const SizedBox(
|
||||||
height: 100,
|
height: 100,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -22,14 +22,16 @@ class ThenAddedTasksContainer extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
String operationValue = '';
|
String operationValue = '';
|
||||||
if (taskList.code.contains('countdown')) {
|
if (taskList.code.contains('countdown')) {
|
||||||
final duration = Duration(
|
final functionValue =
|
||||||
seconds:
|
taskList.functionValue ?? taskList.operationalValues.first.value;
|
||||||
int.tryParse(taskList.operationalValues.first.value.toString()) ??
|
final duration =
|
||||||
0);
|
Duration(seconds: int.tryParse(functionValue.toString()) ?? 0);
|
||||||
operationValue =
|
operationValue =
|
||||||
"${duration.inHours}h ${duration.inMinutes.remainder(60)}m ";
|
"${duration.inHours}h ${duration.inMinutes.remainder(60)}m ";
|
||||||
} else {
|
} else {
|
||||||
operationValue = taskList.operationalValues.first.value.toString();
|
final functionValue =
|
||||||
|
taskList.functionValue ?? taskList.operationalValues.first.value;
|
||||||
|
operationValue = functionValue.toString();
|
||||||
}
|
}
|
||||||
return DefaultContainer(
|
return DefaultContainer(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
|
@ -15,8 +15,11 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|||||||
class ThenDefaultContainer extends StatelessWidget {
|
class ThenDefaultContainer extends StatelessWidget {
|
||||||
const ThenDefaultContainer({
|
const ThenDefaultContainer({
|
||||||
super.key,
|
super.key,
|
||||||
|
required this.sceneId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final String sceneId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DefaultContainer(
|
return DefaultContainer(
|
||||||
@ -47,39 +50,64 @@ class ThenDefaultContainer extends StatelessWidget {
|
|||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
),
|
),
|
||||||
const LightDivider(),
|
const LightDivider(),
|
||||||
BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
sceneId.isNotEmpty
|
||||||
builder: (context, state) {
|
? BlocProvider(
|
||||||
if (state is AddSceneTask) {
|
create: (context) =>
|
||||||
final taskLists = state.tasksList;
|
CreateSceneBloc()..add(FetchSceneTasks(sceneId:sceneId)),
|
||||||
if (taskLists.isNotEmpty) {
|
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||||
return ListView.builder(
|
builder: (context, state) {
|
||||||
shrinkWrap: true,
|
if (state is AddSceneTask) {
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
final taskLists = state.tasksList;
|
||||||
itemCount: taskLists.length,
|
if (taskLists.isNotEmpty) {
|
||||||
itemBuilder: (context, index) {
|
return ListView.builder(
|
||||||
return ThenAddedTasksContainer(
|
shrinkWrap: true,
|
||||||
taskList: taskLists[index],
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
);
|
itemCount: taskLists.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return ThenAddedTasksContainer(
|
||||||
|
taskList: taskLists[index],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
return const SizedBox();
|
||||||
},
|
},
|
||||||
);
|
))
|
||||||
}
|
: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||||
return SceneListTile(
|
builder: (context, state) {
|
||||||
titleString: '+ Add Task',
|
if (state is AddSceneTask) {
|
||||||
textAlign: TextAlign.center,
|
final taskLists = state.tasksList;
|
||||||
onPressed: () => context.customBottomSheet(
|
if (taskLists.isNotEmpty) {
|
||||||
child: const CustomBottomSheetWidget(),
|
return ListView.builder(
|
||||||
),
|
shrinkWrap: true,
|
||||||
);
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
}
|
itemCount: taskLists.length,
|
||||||
return SceneListTile(
|
itemBuilder: (context, index) {
|
||||||
titleString: '+ Add Task',
|
return ThenAddedTasksContainer(
|
||||||
textAlign: TextAlign.center,
|
taskList: taskLists[index],
|
||||||
onPressed: () => context.customBottomSheet(
|
);
|
||||||
child: const CustomBottomSheetWidget(),
|
},
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
},
|
return SceneListTile(
|
||||||
)
|
titleString: '+ Add Task',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
onPressed: () => context.customBottomSheet(
|
||||||
|
child: const CustomBottomSheetWidget(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return SceneListTile(
|
||||||
|
titleString: '+ Add Task',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
onPressed: () => context.customBottomSheet(
|
||||||
|
child: const CustomBottomSheetWidget(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:syncrow_app/features/scene/model/scene_model.dart';
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_item.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_item.dart';
|
||||||
|
|
||||||
class SceneGrid extends StatelessWidget {
|
class SceneGrid extends StatelessWidget {
|
||||||
final List<SceneModel> scenes;
|
final List<ScenesModel> scenes;
|
||||||
final String? loadingSceneId;
|
final String? loadingSceneId;
|
||||||
|
|
||||||
const SceneGrid({
|
const SceneGrid({
|
||||||
|
@ -2,15 +2,18 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.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/bloc/scene_bloc/scene_event.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scene_model.dart';
|
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.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/text_widgets/body_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
|
||||||
import 'package:syncrow_app/generated/assets.dart';
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
class SceneItem extends StatelessWidget {
|
class SceneItem extends StatelessWidget {
|
||||||
final SceneModel scene;
|
final ScenesModel scene;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
|
|
||||||
const SceneItem({
|
const SceneItem({
|
||||||
@ -22,6 +25,17 @@ class SceneItem extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DefaultContainer(
|
return DefaultContainer(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pushNamed(
|
||||||
|
context,
|
||||||
|
Routes.sceneTasksRoute,
|
||||||
|
arguments: SceneSettingsRouteArguments(
|
||||||
|
sceneType: CreateSceneEnum.tabToRun.name,
|
||||||
|
sceneId: scene.id,
|
||||||
|
sceneName: scene.name,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
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_model.dart';
|
import 'package:syncrow_app/features/scene/model/scene_details_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||||
import 'package:syncrow_app/services/api/http_service.dart';
|
import 'package:syncrow_app/services/api/http_service.dart';
|
||||||
|
|
||||||
@ -23,15 +24,15 @@ class SceneApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<SceneModel>> getScenesByUnitId(String unitId) async {
|
static Future<List<ScenesModel>> getScenesByUnitId(String unitId) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.getUnitScenes.replaceAll('{unitUuid}', unitId),
|
path: ApiEndpoints.getUnitScenes.replaceAll('{unitUuid}', unitId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
List<SceneModel> scenes = [];
|
List<ScenesModel> scenes = [];
|
||||||
for (var scene in json) {
|
for (var scene in json) {
|
||||||
scenes.add(SceneModel.fromJson(scene));
|
scenes.add(ScenesModel.fromJson(scene));
|
||||||
}
|
}
|
||||||
return scenes;
|
return scenes;
|
||||||
},
|
},
|
||||||
@ -54,4 +55,23 @@ class SceneApi {
|
|||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//getScene
|
||||||
|
|
||||||
|
static Future<SceneDetailsModel> getSceneDetails(String sceneId) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.get(
|
||||||
|
path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId),
|
||||||
|
showServerMessage: false,
|
||||||
|
expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//deleteScene
|
||||||
|
|
||||||
|
//updateScene
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user