mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
push routine details model and api settup
This commit is contained in:
@ -13,7 +13,7 @@ part 'routine_event.dart';
|
|||||||
part 'routine_state.dart';
|
part 'routine_state.dart';
|
||||||
|
|
||||||
const spaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
const spaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
||||||
const communityId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
const communityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9';
|
||||||
|
|
||||||
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||||
RoutineBloc() : super(const RoutineState()) {
|
RoutineBloc() : super(const RoutineState()) {
|
||||||
|
262
lib/pages/routiens/models/routine_details_model.dart
Normal file
262
lib/pages/routiens/models/routine_details_model.dart
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart';
|
||||||
|
|
||||||
|
class RoutineDetailsModel {
|
||||||
|
final String spaceUuid;
|
||||||
|
final String name;
|
||||||
|
final String decisionExpr;
|
||||||
|
final List<RoutineAction> actions;
|
||||||
|
final String? iconId;
|
||||||
|
final bool? showInDevice;
|
||||||
|
final EffectiveTime? effectiveTime;
|
||||||
|
final List<RoutineCondition>? conditions;
|
||||||
|
final String? type;
|
||||||
|
|
||||||
|
RoutineDetailsModel({
|
||||||
|
required this.spaceUuid,
|
||||||
|
required this.name,
|
||||||
|
required this.decisionExpr,
|
||||||
|
required this.actions,
|
||||||
|
this.iconId,
|
||||||
|
this.showInDevice,
|
||||||
|
this.effectiveTime,
|
||||||
|
this.conditions,
|
||||||
|
this.type,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Convert to CreateSceneModel
|
||||||
|
CreateSceneModel toCreateSceneModel() {
|
||||||
|
return CreateSceneModel(
|
||||||
|
spaceUuid: spaceUuid,
|
||||||
|
iconId: iconId ?? '',
|
||||||
|
showInDevice: showInDevice ?? false,
|
||||||
|
sceneName: name,
|
||||||
|
decisionExpr: decisionExpr,
|
||||||
|
actions: actions.map((a) => a.toCreateSceneAction()).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to CreateAutomationModel
|
||||||
|
CreateAutomationModel toCreateAutomationModel() {
|
||||||
|
return CreateAutomationModel(
|
||||||
|
spaceUuid: spaceUuid,
|
||||||
|
automationName: name,
|
||||||
|
decisionExpr: decisionExpr,
|
||||||
|
effectiveTime:
|
||||||
|
effectiveTime ?? EffectiveTime(start: '', end: '', loops: ''),
|
||||||
|
conditions: conditions?.map((c) => c.toCondition()).toList() ?? [],
|
||||||
|
actions: actions.map((a) => a.toAutomationAction()).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'spaceUuid': spaceUuid,
|
||||||
|
'name': name,
|
||||||
|
'decisionExpr': decisionExpr,
|
||||||
|
'actions': actions.map((x) => x.toMap()).toList(),
|
||||||
|
if (iconId != null) 'iconId': iconId,
|
||||||
|
if (showInDevice != null) 'showInDevice': showInDevice,
|
||||||
|
if (effectiveTime != null) 'effectiveTime': effectiveTime!.toMap(),
|
||||||
|
if (conditions != null)
|
||||||
|
'conditions': conditions!.map((x) => x.toMap()).toList(),
|
||||||
|
if (type != null) 'type': type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory RoutineDetailsModel.fromMap(Map<String, dynamic> map) {
|
||||||
|
return RoutineDetailsModel(
|
||||||
|
spaceUuid: map['spaceUuid'] ?? '',
|
||||||
|
name: map['name'] ?? '',
|
||||||
|
decisionExpr: map['decisionExpr'] ?? '',
|
||||||
|
actions: List<RoutineAction>.from(
|
||||||
|
map['actions']?.map((x) => RoutineAction.fromMap(x)) ?? [],
|
||||||
|
),
|
||||||
|
iconId: map['iconId'],
|
||||||
|
showInDevice: map['showInDevice'],
|
||||||
|
effectiveTime: map['effectiveTime'] != null
|
||||||
|
? EffectiveTime.fromMap(map['effectiveTime'])
|
||||||
|
: null,
|
||||||
|
conditions: map['conditions'] != null
|
||||||
|
? List<RoutineCondition>.from(
|
||||||
|
map['conditions'].map((x) => RoutineCondition.fromMap(x)))
|
||||||
|
: null,
|
||||||
|
type: map['type'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String toJson() => json.encode(toMap());
|
||||||
|
|
||||||
|
factory RoutineDetailsModel.fromJson(String source) =>
|
||||||
|
RoutineDetailsModel.fromMap(json.decode(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
class RoutineAction {
|
||||||
|
final String entityId;
|
||||||
|
final String actionExecutor;
|
||||||
|
final RoutineExecutorProperty? executorProperty;
|
||||||
|
|
||||||
|
RoutineAction({
|
||||||
|
required this.entityId,
|
||||||
|
required this.actionExecutor,
|
||||||
|
this.executorProperty,
|
||||||
|
});
|
||||||
|
|
||||||
|
CreateSceneAction toCreateSceneAction() {
|
||||||
|
return CreateSceneAction(
|
||||||
|
entityId: entityId,
|
||||||
|
actionExecutor: actionExecutor,
|
||||||
|
executorProperty: executorProperty?.toCreateSceneExecutorProperty(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
AutomationAction toAutomationAction() {
|
||||||
|
return AutomationAction(
|
||||||
|
entityId: entityId,
|
||||||
|
actionExecutor: actionExecutor,
|
||||||
|
executorProperty: executorProperty?.toExecutorProperty(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'entityId': entityId,
|
||||||
|
'actionExecutor': actionExecutor,
|
||||||
|
if (executorProperty != null)
|
||||||
|
'executorProperty': executorProperty!.toMap(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory RoutineAction.fromMap(Map<String, dynamic> map) {
|
||||||
|
return RoutineAction(
|
||||||
|
entityId: map['entityId'] ?? '',
|
||||||
|
actionExecutor: map['actionExecutor'] ?? '',
|
||||||
|
executorProperty: map['executorProperty'] != null
|
||||||
|
? RoutineExecutorProperty.fromMap(map['executorProperty'])
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RoutineExecutorProperty {
|
||||||
|
final String? functionCode;
|
||||||
|
final dynamic functionValue;
|
||||||
|
final int? delaySeconds;
|
||||||
|
|
||||||
|
RoutineExecutorProperty({
|
||||||
|
this.functionCode,
|
||||||
|
this.functionValue,
|
||||||
|
this.delaySeconds,
|
||||||
|
});
|
||||||
|
|
||||||
|
CreateSceneExecutorProperty toCreateSceneExecutorProperty() {
|
||||||
|
return CreateSceneExecutorProperty(
|
||||||
|
functionCode: functionCode ?? '',
|
||||||
|
functionValue: functionValue,
|
||||||
|
delaySeconds: delaySeconds ?? 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExecutorProperty toExecutorProperty() {
|
||||||
|
return ExecutorProperty(
|
||||||
|
functionCode: functionCode,
|
||||||
|
functionValue: functionValue,
|
||||||
|
delaySeconds: delaySeconds,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
if (functionCode != null) 'functionCode': functionCode,
|
||||||
|
if (functionValue != null) 'functionValue': functionValue,
|
||||||
|
if (delaySeconds != null) 'delaySeconds': delaySeconds,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory RoutineExecutorProperty.fromMap(Map<String, dynamic> map) {
|
||||||
|
return RoutineExecutorProperty(
|
||||||
|
functionCode: map['functionCode'],
|
||||||
|
functionValue: map['functionValue'],
|
||||||
|
delaySeconds: map['delaySeconds']?.toInt(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RoutineCondition {
|
||||||
|
final int code;
|
||||||
|
final String entityId;
|
||||||
|
final String entityType;
|
||||||
|
final RoutineConditionExpr expr;
|
||||||
|
|
||||||
|
RoutineCondition({
|
||||||
|
required this.code,
|
||||||
|
required this.entityId,
|
||||||
|
required this.entityType,
|
||||||
|
required this.expr,
|
||||||
|
});
|
||||||
|
|
||||||
|
Condition toCondition() {
|
||||||
|
return Condition(
|
||||||
|
code: code,
|
||||||
|
entityId: entityId,
|
||||||
|
entityType: entityType,
|
||||||
|
expr: expr.toConditionExpr(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'code': code,
|
||||||
|
'entityId': entityId,
|
||||||
|
'entityType': entityType,
|
||||||
|
'expr': expr.toMap(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory RoutineCondition.fromMap(Map<String, dynamic> map) {
|
||||||
|
return RoutineCondition(
|
||||||
|
code: map['code']?.toInt() ?? 0,
|
||||||
|
entityId: map['entityId'] ?? '',
|
||||||
|
entityType: map['entityType'] ?? '',
|
||||||
|
expr: RoutineConditionExpr.fromMap(map['expr']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RoutineConditionExpr {
|
||||||
|
final String statusCode;
|
||||||
|
final String comparator;
|
||||||
|
final dynamic statusValue;
|
||||||
|
|
||||||
|
RoutineConditionExpr({
|
||||||
|
required this.statusCode,
|
||||||
|
required this.comparator,
|
||||||
|
required this.statusValue,
|
||||||
|
});
|
||||||
|
|
||||||
|
ConditionExpr toConditionExpr() {
|
||||||
|
return ConditionExpr(
|
||||||
|
statusCode: statusCode,
|
||||||
|
comparator: comparator,
|
||||||
|
statusValue: statusValue,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'statusCode': statusCode,
|
||||||
|
'comparator': comparator,
|
||||||
|
'statusValue': statusValue,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory RoutineConditionExpr.fromMap(Map<String, dynamic> map) {
|
||||||
|
return RoutineConditionExpr(
|
||||||
|
statusCode: map['statusCode'] ?? '',
|
||||||
|
comparator: map['comparator'] ?? '',
|
||||||
|
statusValue: map['statusValue'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,10 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
class ScenesModel {
|
class ScenesModel {
|
||||||
final String id;
|
final String id;
|
||||||
|
final String? sceneTuyaId;
|
||||||
final String name;
|
final String name;
|
||||||
final String status;
|
final String status;
|
||||||
final String type;
|
final String type;
|
||||||
@ -9,26 +12,36 @@ class ScenesModel {
|
|||||||
|
|
||||||
ScenesModel({
|
ScenesModel({
|
||||||
required this.id,
|
required this.id,
|
||||||
|
this.sceneTuyaId,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.status,
|
required this.status,
|
||||||
required this.type,
|
required this.type,
|
||||||
this.icon,
|
this.icon,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
factory ScenesModel.fromRawJson(String str) =>
|
||||||
|
ScenesModel.fromJson(json.decode(str));
|
||||||
|
|
||||||
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
|
Uint8List get iconInBytes => base64Decode(icon ?? '');
|
||||||
|
|
||||||
factory ScenesModel.fromJson(Map<String, dynamic> json,
|
factory ScenesModel.fromJson(Map<String, dynamic> json,
|
||||||
{bool? isAutomation}) =>
|
{bool? isAutomation}) {
|
||||||
ScenesModel(
|
return ScenesModel(
|
||||||
id: json["id"],
|
id: json["id"] ?? json["uuid"] ?? '',
|
||||||
name: json["name"] ?? '',
|
sceneTuyaId: json["sceneTuyaId"] as String?,
|
||||||
status: json["status"] ?? '',
|
name: json["name"] ?? '',
|
||||||
type: json["type"] ?? '',
|
status: json["status"] ?? '',
|
||||||
icon: isAutomation == true
|
type: json["type"] ?? '',
|
||||||
? Assets.automation
|
icon:
|
||||||
: (json["icon"] as String?),
|
isAutomation == true ? Assets.automation : (json["icon"] as String?),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
"id": id,
|
"id": id,
|
||||||
|
"sceneTuyaId": sceneTuyaId ?? '',
|
||||||
"name": name,
|
"name": name,
|
||||||
"status": status,
|
"status": status,
|
||||||
"type": type,
|
"type": type,
|
||||||
|
@ -47,7 +47,7 @@ class RoutinesView extends StatelessWidget {
|
|||||||
textString: '',
|
textString: '',
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 30,
|
height: 15,
|
||||||
),
|
),
|
||||||
const Expanded(child: FetchRoutineScenesAutomation()),
|
const Expanded(child: FetchRoutineScenesAutomation()),
|
||||||
],
|
],
|
||||||
|
@ -5,6 +5,7 @@ import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/routine_vie
|
|||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class FetchRoutineScenesAutomation extends StatefulWidget {
|
class FetchRoutineScenesAutomation extends StatefulWidget {
|
||||||
const FetchRoutineScenesAutomation({super.key});
|
const FetchRoutineScenesAutomation({super.key});
|
||||||
@ -14,7 +15,8 @@ class FetchRoutineScenesAutomation extends StatefulWidget {
|
|||||||
_FetchRoutineScenesState();
|
_FetchRoutineScenesState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation> {
|
class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
||||||
|
with HelperResponsiveLayout {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -27,83 +29,94 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return SizedBox(
|
return SingleChildScrollView(
|
||||||
height: 500,
|
child: Padding(
|
||||||
child: Column(
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
if (state.isLoading)
|
mainAxisSize: MainAxisSize.min,
|
||||||
const Center(
|
children: [
|
||||||
child: CircularProgressIndicator(),
|
if (state.isLoading)
|
||||||
),
|
const Center(
|
||||||
Text(
|
child: CircularProgressIndicator(),
|
||||||
"Scenes (Tab to Run)",
|
),
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
||||||
color: ColorsManager.grayColor,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
if (state.scenes.isEmpty)
|
|
||||||
Text(
|
Text(
|
||||||
"No scenes found",
|
"Scenes (Tab to Run)",
|
||||||
style: context.textTheme.bodyMedium?.copyWith(
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
color: ColorsManager.grayColor,
|
color: ColorsManager.grayColor,
|
||||||
),
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
if (state.scenes.isNotEmpty)
|
const SizedBox(height: 10),
|
||||||
SizedBox(
|
if (state.scenes.isEmpty)
|
||||||
height: 200,
|
Text(
|
||||||
child: ListView.builder(
|
"No scenes found",
|
||||||
shrinkWrap: true,
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: state.scenes.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return RoutineViewCard(
|
|
||||||
onTap: () {},
|
|
||||||
textString: state.scenes[index].name,
|
|
||||||
icon: state.scenes[index].icon ?? Assets.logoHorizontal,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 30),
|
|
||||||
Text(
|
|
||||||
"Automations",
|
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
||||||
color: ColorsManager.grayColor,
|
color: ColorsManager.grayColor,
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
),
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
if (state.automations.isEmpty)
|
|
||||||
Text(
|
|
||||||
"No automations found",
|
|
||||||
style: context.textTheme.bodyMedium?.copyWith(
|
|
||||||
color: ColorsManager.grayColor,
|
|
||||||
),
|
),
|
||||||
|
if (state.scenes.isNotEmpty)
|
||||||
|
ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
maxHeight: isSmallScreenSize(context) ? 160 : 170,
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: state.scenes.length,
|
||||||
|
itemBuilder: (context, index) => Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
||||||
|
),
|
||||||
|
child: RoutineViewCard(
|
||||||
|
onTap: () {},
|
||||||
|
textString: state.scenes[index].name,
|
||||||
|
icon:
|
||||||
|
state.scenes[index].icon ?? Assets.logoHorizontal,
|
||||||
|
isFromScenes: true,
|
||||||
|
iconInBytes: state.scenes[index].iconInBytes,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
Text(
|
||||||
|
"Automations",
|
||||||
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
|
color: ColorsManager.grayColor,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
if (state.automations.isNotEmpty)
|
const SizedBox(height: 10),
|
||||||
SizedBox(
|
if (state.automations.isEmpty)
|
||||||
height: 200,
|
Text(
|
||||||
child: ListView.builder(
|
"No automations found",
|
||||||
shrinkWrap: true,
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
scrollDirection: Axis.horizontal,
|
color: ColorsManager.grayColor,
|
||||||
itemCount: state.automations.length,
|
),
|
||||||
itemBuilder: (context, index) {
|
),
|
||||||
return Padding(
|
if (state.automations.isNotEmpty)
|
||||||
padding: const EdgeInsets.only(right: 8.0),
|
ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
maxHeight: isSmallScreenSize(context) ? 160 : 170,
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: state.automations.length,
|
||||||
|
itemBuilder: (context, index) => Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
||||||
|
),
|
||||||
child: RoutineViewCard(
|
child: RoutineViewCard(
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
textString: state.automations[index].name,
|
textString: state.automations[index].name,
|
||||||
icon: state.automations[index].icon ??
|
icon: state.automations[index].icon ??
|
||||||
Assets.automation,
|
Assets.automation,
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -1,84 +1,124 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class RoutineViewCard extends StatelessWidget {
|
class RoutineViewCard extends StatelessWidget with HelperResponsiveLayout {
|
||||||
const RoutineViewCard({
|
const RoutineViewCard({
|
||||||
super.key,
|
super.key,
|
||||||
required this.onTap,
|
required this.onTap,
|
||||||
required this.icon,
|
required this.icon,
|
||||||
required this.textString,
|
required this.textString,
|
||||||
|
this.isFromScenes,
|
||||||
|
this.iconInBytes,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Function() onTap;
|
final Function() onTap;
|
||||||
final dynamic icon;
|
final dynamic icon;
|
||||||
final String textString;
|
final String textString;
|
||||||
|
final bool? isFromScenes;
|
||||||
|
final Uint8List? iconInBytes;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SizedBox(
|
final double cardWidth = isSmallScreenSize(context)
|
||||||
height: 200,
|
? 120
|
||||||
width: 150,
|
: isMediumScreenSize(context)
|
||||||
child: GestureDetector(
|
? 135
|
||||||
onTap: () {
|
: 150;
|
||||||
onTap();
|
|
||||||
},
|
final double cardHeight = isSmallScreenSize(context) ? 160 : 170;
|
||||||
child: Card(
|
|
||||||
elevation: 3,
|
final double iconSize = isSmallScreenSize(context)
|
||||||
shape: RoundedRectangleBorder(
|
? 50
|
||||||
borderRadius: BorderRadius.circular(10),
|
: isMediumScreenSize(context)
|
||||||
),
|
? 60
|
||||||
color: ColorsManager.whiteColors,
|
: 70;
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
return ConstrainedBox(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
constraints: BoxConstraints(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
maxWidth: cardWidth,
|
||||||
children: [
|
maxHeight: cardHeight,
|
||||||
Center(
|
),
|
||||||
child: Container(
|
child: Card(
|
||||||
decoration: BoxDecoration(
|
elevation: 3,
|
||||||
color: ColorsManager.graysColor,
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(120),
|
borderRadius: BorderRadius.circular(10),
|
||||||
border: Border.all(
|
),
|
||||||
color: ColorsManager.greyColor,
|
color: ColorsManager.whiteColors,
|
||||||
width: 2.0,
|
child: InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: ColorsManager.graysColor,
|
||||||
|
borderRadius: BorderRadius.circular(120),
|
||||||
|
border: Border.all(
|
||||||
|
color: ColorsManager.greyColor,
|
||||||
|
width: 2.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
height: iconSize,
|
||||||
|
width: iconSize,
|
||||||
|
child: (isFromScenes ?? false)
|
||||||
|
? (iconInBytes != null &&
|
||||||
|
iconInBytes?.isNotEmpty == true)
|
||||||
|
? Image.memory(
|
||||||
|
iconInBytes!,
|
||||||
|
height: iconSize,
|
||||||
|
width: iconSize,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
errorBuilder: (context, error, stackTrace) =>
|
||||||
|
Image.asset(
|
||||||
|
Assets.logo,
|
||||||
|
height: iconSize,
|
||||||
|
width: iconSize,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Image.asset(
|
||||||
|
Assets.logo,
|
||||||
|
height: iconSize,
|
||||||
|
width: iconSize,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
)
|
||||||
|
: (icon is String && icon.endsWith('.svg'))
|
||||||
|
? SvgPicture.asset(
|
||||||
|
icon,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
)
|
||||||
|
: Icon(
|
||||||
|
icon,
|
||||||
|
color: ColorsManager.dialogBlueTitle,
|
||||||
|
size: isSmallScreenSize(context) ? 30 : 40,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 3),
|
||||||
|
child: Text(
|
||||||
|
textString,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 2,
|
||||||
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
fontSize: isSmallScreenSize(context) ? 10 : 12,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
height: 70,
|
|
||||||
width: 70,
|
|
||||||
child: (icon is String)
|
|
||||||
? icon.endsWith('.svg')
|
|
||||||
? SvgPicture.asset(
|
|
||||||
icon,
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
)
|
|
||||||
: Image.asset(
|
|
||||||
icon,
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
)
|
|
||||||
: Icon(
|
|
||||||
icon,
|
|
||||||
color: ColorsManager.dialogBlueTitle,
|
|
||||||
size: 40,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
const SizedBox(height: 8),
|
),
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 3),
|
|
||||||
child: Text(
|
|
||||||
textString,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
maxLines: 2,
|
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
|
||||||
color: ColorsManager.blackColor,
|
|
||||||
fontSize: 12,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/icon_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/icon_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/models/routine_details_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/routine_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/routine_model.dart';
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||||
@ -67,9 +68,9 @@ class SceneApi {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get scene by unit id
|
//get scenes by community id and space id
|
||||||
|
|
||||||
static Future<List<ScenesModel>> getScenesByUnitId(
|
static Future<List<ScenesModel>> getScenesByUnitId(
|
||||||
String unitId, String communityId,
|
String unitId, String communityId,
|
||||||
{showInDevice = false}) async {
|
{showInDevice = false}) async {
|
||||||
try {
|
try {
|
||||||
@ -95,25 +96,6 @@ class SceneApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static Future<List<ScenesModel>> getScenesByUnitId(String unitId) async {
|
|
||||||
// try {
|
|
||||||
// final response = await _httpService.get(
|
|
||||||
// path: ApiEndpoints.getSpaceScenes.replaceAll('{unitUuid}', unitId),
|
|
||||||
// showServerMessage: false,
|
|
||||||
// expectedResponseModel: (json) {
|
|
||||||
// List<ScenesModel> scenes = [];
|
|
||||||
// for (var scene in json) {
|
|
||||||
// scenes.add(ScenesModel.fromJson(scene));
|
|
||||||
// }
|
|
||||||
// return scenes;
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// return response;
|
|
||||||
// } catch (e) {
|
|
||||||
// rethrow;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//getAutomation
|
//getAutomation
|
||||||
|
|
||||||
static Future<List<ScenesModel>> getAutomationByUnitId(String unitId) async {
|
static Future<List<ScenesModel>> getAutomationByUnitId(String unitId) async {
|
||||||
@ -148,21 +130,21 @@ class SceneApi {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// //automation details
|
//automation details
|
||||||
// static Future<SceneDetailsModel> getAutomationDetails(
|
static Future<RoutineDetailsModel> getAutomationDetails(
|
||||||
// String automationId) async {
|
String automationId) async {
|
||||||
// try {
|
try {
|
||||||
// final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
// path: ApiEndpoints.getAutomationDetails
|
path: ApiEndpoints.getAutomationDetails
|
||||||
// .replaceAll('{automationId}', automationId),
|
.replaceAll('{automationId}', automationId),
|
||||||
// showServerMessage: false,
|
showServerMessage: false,
|
||||||
// expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
|
expectedResponseModel: (json) => RoutineDetailsModel.fromJson(json),
|
||||||
// );
|
);
|
||||||
// return response;
|
return response;
|
||||||
// } catch (e) {
|
} catch (e) {
|
||||||
// rethrow;
|
rethrow;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
//
|
||||||
// //updateAutomationStatus
|
// //updateAutomationStatus
|
||||||
// static Future<bool> updateAutomationStatus(String automationId,
|
// static Future<bool> updateAutomationStatus(String automationId,
|
||||||
@ -180,20 +162,19 @@ class SceneApi {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// //getScene
|
//getScene
|
||||||
//
|
static Future<RoutineDetailsModel> getSceneDetails(String sceneId) async {
|
||||||
// static Future<SceneDetailsModel> getSceneDetails(String sceneId) async {
|
try {
|
||||||
// try {
|
final response = await _httpService.get(
|
||||||
// final response = await _httpService.get(
|
path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId),
|
||||||
// path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId),
|
showServerMessage: false,
|
||||||
// showServerMessage: false,
|
expectedResponseModel: (json) => RoutineDetailsModel.fromJson(json),
|
||||||
// expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
|
);
|
||||||
// );
|
return response;
|
||||||
// return response;
|
} catch (e) {
|
||||||
// } catch (e) {
|
rethrow;
|
||||||
// rethrow;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
// //update Scene
|
// //update Scene
|
||||||
// static updateScene(CreateSceneModel createSceneModel, String sceneId) async {
|
// static updateScene(CreateSceneModel createSceneModel, String sceneId) async {
|
||||||
|
@ -46,7 +46,6 @@ abstract class ApiEndpoints {
|
|||||||
'/schedule/{deviceUuid}/{scheduleUuid}';
|
'/schedule/{deviceUuid}/{scheduleUuid}';
|
||||||
static const String updateScheduleByDeviceId =
|
static const String updateScheduleByDeviceId =
|
||||||
'/schedule/enable/{deviceUuid}';
|
'/schedule/enable/{deviceUuid}';
|
||||||
|
|
||||||
static const String factoryReset = '/device/factory/reset/{deviceUuid}';
|
static const String factoryReset = '/device/factory/reset/{deviceUuid}';
|
||||||
static const String powerClamp =
|
static const String powerClamp =
|
||||||
'/device/{powerClampUuid}/power-clamp/status';
|
'/device/{powerClampUuid}/power-clamp/status';
|
||||||
@ -57,4 +56,7 @@ abstract class ApiEndpoints {
|
|||||||
static const String createAutomation = '/automation';
|
static const String createAutomation = '/automation';
|
||||||
static const String getUnitScenes =
|
static const String getUnitScenes =
|
||||||
'/communities/{communityUuid}/spaces/{spaceUuid}/scenes';
|
'/communities/{communityUuid}/spaces/{spaceUuid}/scenes';
|
||||||
|
static const String getAutomationDetails =
|
||||||
|
'/automation/details/{automationId}';
|
||||||
|
static const String getScene = '/scene/tap-to-run/{sceneId}';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user