mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 04:19:40 +00:00
4scene
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_event.dart';
|
||||
@ -27,9 +26,8 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
FourSceneBloc({
|
||||
required this.fourSceneId,
|
||||
}) : super(const FourSceneState()) {
|
||||
on<FourSceneInitial>(_fetchStatus);
|
||||
on<FourSceneInitialInfo>(fetchDeviceData);
|
||||
on<ReportLogsInitial>(fetchLogsForLastMonth);
|
||||
on<FourSceneInitial>(_fetchDeviceStatus);
|
||||
on<FourSceneInitialInfo>(fetchDeviceInfo);
|
||||
on<SaveNameEvent>(saveName);
|
||||
on<ToggleNotificationEvent>(_toggleNotification);
|
||||
on<ChangeNameEvent>(_changeName);
|
||||
@ -47,6 +45,8 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
on<FetchDeviceScene>(_fetchDeviceScene);
|
||||
on<ControlDeviceScene>(_controlDevice);
|
||||
on<FourSceneSwitchInitial>(_fetchFourSceneSwitches);
|
||||
on<AssignDeviceScene>(assignScene);
|
||||
on<GetSceneBySwitchName>(getSceneByName);
|
||||
}
|
||||
|
||||
final TextEditingController nameController =
|
||||
@ -99,7 +99,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
subspaceName: "",
|
||||
),
|
||||
);
|
||||
|
||||
String sceneId = '';
|
||||
Future<void> saveName(
|
||||
SaveNameEvent event, Emitter<FourSceneState> emit) async {
|
||||
if (_validateInputs()) return;
|
||||
@ -125,27 +125,36 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
FourSceneSwitchInitial event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
List<dynamic> response = await DevicesAPI.getFourSceneInfo(fourSceneId);
|
||||
fourScene =
|
||||
response.map((item) => FourSceneSwitchModel.fromJson(item)).toList();
|
||||
_rankFourSceneSwitches();
|
||||
var response = await DevicesAPI.getFourSceneInfo(fourSceneId);
|
||||
Map<String, String> sceneTitles = {
|
||||
"scene_1": '',
|
||||
"scene_2": '',
|
||||
"scene_3": '',
|
||||
"scene_4": ''
|
||||
};
|
||||
for (var item in response) {
|
||||
if (item["switchName"] != null) {
|
||||
sceneTitles[item["switchName"]] = item["scene"]["name"] ?? '';
|
||||
}
|
||||
}
|
||||
print('object======4${response}');
|
||||
|
||||
FourSceneModelState deviceStatus = FourSceneModelState(
|
||||
scene_1: sceneTitles["scene_1"] ?? '',
|
||||
scene_2: sceneTitles["scene_2"] ?? '',
|
||||
scene_3: sceneTitles["scene_3"] ?? '',
|
||||
scene_4: sceneTitles["scene_4"] ?? '',
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '',
|
||||
);
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _rankFourSceneSwitches() {
|
||||
const switchOrder = ['scene_1', 'scene_2', 'scene_3', 'scene_4'];
|
||||
fourScene.sort((a, b) {
|
||||
return switchOrder
|
||||
.indexOf(a.switchName)
|
||||
.compareTo(switchOrder.indexOf(b.switchName));
|
||||
});
|
||||
}
|
||||
|
||||
void _fetchStatus(
|
||||
void _fetchDeviceStatus(
|
||||
FourSceneInitial event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
@ -157,15 +166,41 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
deviceStatus = FourSceneModelState.fromJson(
|
||||
statusModelList,
|
||||
);
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
// _listenToChanges();
|
||||
add(const FourSceneSwitchInitial());
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void assignScene(
|
||||
AssignDeviceScene event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
final response = await DevicesAPI.postFourSceneInfo(
|
||||
deviceId: fourSceneId,
|
||||
sceneUuid: event.sceneUuid,
|
||||
spaceUuid: event.unit!.id,
|
||||
switchName: event.switchName);
|
||||
emit(SaveSelectionSuccessState());
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void getSceneByName(
|
||||
GetSceneBySwitchName event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
final response = await DevicesAPI.getSceneBySwitchName(
|
||||
deviceId: fourSceneId, switchName: event.switchName);
|
||||
sceneId = response['scene']['uuid'];
|
||||
emit(SaveSelectionSuccessState());
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void _fetchDeviceScene(
|
||||
FetchDeviceScene event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
@ -180,7 +215,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
);
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
// _listenToChanges();
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
@ -208,13 +242,17 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future fetchDeviceData(
|
||||
Future fetchDeviceInfo(
|
||||
FourSceneInitialInfo event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
var response = await DevicesAPI.getDeviceInfo(fourSceneId);
|
||||
deviceInfo = SceneSwitch.fromJson(response);
|
||||
deviceName = deviceInfo.name;
|
||||
emit(LoadingDeviceInfo(deviceInfo: deviceInfo));
|
||||
try {
|
||||
emit(FourSceneLoadingState());
|
||||
var response = await DevicesAPI.getDeviceInfo(fourSceneId);
|
||||
deviceInfo = SceneSwitch.fromJson(response);
|
||||
deviceName = deviceInfo.name;
|
||||
emit(LoadingDeviceInfo(deviceInfo: deviceInfo));
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void _onSearchFaq(SearchFaqEvent event, Emitter<FourSceneState> emit) {
|
||||
@ -263,29 +301,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
DeviceReport recordGroups =
|
||||
DeviceReport(startTime: '0', endTime: '0', data: []);
|
||||
|
||||
Future<void> fetchLogsForLastMonth(
|
||||
ReportLogsInitial event, Emitter<FourSceneState> emit) async {
|
||||
DateTime now = DateTime.now();
|
||||
DateTime lastMonth = DateTime(now.year, now.month - 1, now.day);
|
||||
int startTime = lastMonth.millisecondsSinceEpoch;
|
||||
int endTime = now.millisecondsSinceEpoch;
|
||||
try {
|
||||
emit(FourSceneLoadingState());
|
||||
var response = await DevicesAPI.getReportLogs(
|
||||
startTime: startTime.toString(),
|
||||
endTime: endTime.toString(),
|
||||
deviceUuid: fourSceneId,
|
||||
code: 'sossensor_state',
|
||||
);
|
||||
recordGroups = response;
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
String errorMessage = errorData['message'];
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
final List<FourSceneQuestionModel> faqQuestions = [
|
||||
FourSceneQuestionModel(
|
||||
id: 1,
|
||||
@ -487,18 +502,11 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
if (value == null) return 'name is required';
|
||||
final withoutExtraSpaces = value.replaceAll(RegExp(r"\s+"), ' ').trim();
|
||||
if (withoutExtraSpaces.length < 2 || withoutExtraSpaces.length > 30) {
|
||||
return 'Full name must be between 2 and 30 characters long';
|
||||
return 'name must be between 2 and 30 characters long';
|
||||
}
|
||||
// Test if it contains anything but alphanumeric spaces and single quote
|
||||
if (RegExp(r"/[^ a-zA-Z0-9-\']/").hasMatch(withoutExtraSpaces)) {
|
||||
return 'Only alphanumeric characters, space, dash and single quote are allowed';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
String scene1 = 'scene_1';
|
||||
String scene2 = 'scene_2';
|
||||
String scene3 = 'scene_3';
|
||||
String scene4 = 'scene_4';
|
||||
}
|
||||
|
@ -212,3 +212,20 @@ class ControlDeviceScene extends FourSceneEvent {
|
||||
class FourSceneSwitchInitial extends FourSceneEvent {
|
||||
const FourSceneSwitchInitial();
|
||||
}
|
||||
class SaveSelectionSceneEvent extends FourSceneEvent {
|
||||
const SaveSelectionSceneEvent();
|
||||
}
|
||||
|
||||
class AssignDeviceScene extends FourSceneEvent {
|
||||
final String? sceneUuid;
|
||||
final String? switchName;
|
||||
final SpaceModel? unit;
|
||||
const AssignDeviceScene({this.sceneUuid, this.unit,this.switchName});
|
||||
}
|
||||
|
||||
|
||||
class GetSceneBySwitchName extends FourSceneEvent {
|
||||
final String? switchName;
|
||||
|
||||
const GetSceneBySwitchName({this.switchName});
|
||||
}
|
@ -54,7 +54,7 @@ class LoadingNewSate extends FourSceneState {
|
||||
class NameEditingState extends FourSceneState {
|
||||
final bool editName;
|
||||
|
||||
NameEditingState({required this.editName});
|
||||
const NameEditingState({required this.editName});
|
||||
}
|
||||
|
||||
class FaqLoadedState extends FourSceneState {
|
||||
@ -97,6 +97,7 @@ class SceneLoaded extends FourSceneState {
|
||||
class SelectedSceneState extends FourSceneState {}
|
||||
|
||||
class SearchResultsState extends FourSceneState {}
|
||||
|
||||
class SaveState extends FourSceneState {}
|
||||
|
||||
class SaveSelectionSuccessState extends FourSceneState {}
|
||||
@ -114,11 +115,10 @@ class OptionSelectedState extends FourSceneState {
|
||||
List<Object> get props => [selectedOption, hasSelectionChanged];
|
||||
}
|
||||
|
||||
|
||||
class LoadingDeviceInfo extends FourSceneState {
|
||||
final SceneSwitch deviceInfo;
|
||||
const LoadingDeviceInfo({required this.deviceInfo});
|
||||
|
||||
@override
|
||||
List<Object> get props => [deviceInfo];
|
||||
}
|
||||
}
|
||||
|
@ -7,19 +7,25 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
class SelectSwitchDialog extends StatefulWidget {
|
||||
final Function()? cancelTab;
|
||||
final Function()? confirmTab;
|
||||
|
||||
const SelectSwitchDialog({
|
||||
super.key,
|
||||
required this.cancelTab,
|
||||
required this.confirmTab,
|
||||
});
|
||||
String? switch1Title;
|
||||
String? switch2Title;
|
||||
String? switch3Title;
|
||||
String? switch4Title;
|
||||
SelectSwitchDialog(
|
||||
{super.key,
|
||||
required this.cancelTab,
|
||||
required this.confirmTab,
|
||||
this.switch1Title,
|
||||
this.switch2Title,
|
||||
this.switch3Title,
|
||||
this.switch4Title});
|
||||
|
||||
@override
|
||||
State<SelectSwitchDialog> createState() => _SelectSwitchDialogState();
|
||||
}
|
||||
|
||||
class _SelectSwitchDialogState extends State<SelectSwitchDialog> {
|
||||
int? selectedSwitchIndex = 0; // State variable to track selected switch
|
||||
int? selectedSwitchIndex = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -44,6 +50,10 @@ class _SelectSwitchDialogState extends State<SelectSwitchDialog> {
|
||||
Row(
|
||||
children: [
|
||||
SwitchsCard(
|
||||
switch1Title: widget.switch1Title,
|
||||
switch2Title: widget.switch2Title,
|
||||
switch3Title: widget.switch3Title,
|
||||
switch4Title: widget.switch4Title,
|
||||
switch1Down: selectedSwitchIndex == -1
|
||||
? Assets.removeSceneIcon
|
||||
: Assets.addSwitchIcon,
|
||||
@ -56,7 +66,6 @@ class _SelectSwitchDialogState extends State<SelectSwitchDialog> {
|
||||
switch2Up: selectedSwitchIndex == 2
|
||||
? Assets.removeSceneIcon
|
||||
: Assets.addSwitchIcon,
|
||||
|
||||
onSwitch1UpTap: () {
|
||||
setState(() => selectedSwitchIndex = 1);
|
||||
},
|
||||
@ -69,8 +78,6 @@ class _SelectSwitchDialogState extends State<SelectSwitchDialog> {
|
||||
onSwitch2DownTap: () {
|
||||
setState(() => selectedSwitchIndex = -2);
|
||||
},
|
||||
|
||||
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -70,6 +70,10 @@ class SixSceneScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
SwitchsCard(
|
||||
// switch1Title: ,
|
||||
// switch2Title: ,
|
||||
// switch3Title: ,
|
||||
// switch4Title: ,
|
||||
switch1Down: sensor.switchStatus == true
|
||||
? Assets.switchOn
|
||||
: Assets.switchOff,
|
||||
@ -95,7 +99,6 @@ class SixSceneScreen extends StatelessWidget {
|
||||
onSwitch2DownTap: () {
|
||||
debugPrint("Switch 2 Down tapped");
|
||||
},
|
||||
|
||||
),
|
||||
Flexible(
|
||||
child: Row(
|
||||
|
@ -1,8 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class SwitchsCard extends StatelessWidget {
|
||||
final String? switch1Title;
|
||||
final String? switch2Title;
|
||||
final String? switch3Title;
|
||||
final String? switch4Title;
|
||||
|
||||
final String switch1Up;
|
||||
final String switch1Down;
|
||||
final String switch2Up;
|
||||
@ -22,6 +28,10 @@ class SwitchsCard extends StatelessWidget {
|
||||
required this.onSwitch1DownTap,
|
||||
required this.onSwitch2UpTap,
|
||||
required this.onSwitch2DownTap,
|
||||
this.switch1Title,
|
||||
this.switch2Title,
|
||||
this.switch3Title,
|
||||
this.switch4Title,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -74,12 +84,22 @@ class SwitchsCard extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
// Switch 1
|
||||
_buildSwitchColumn(switch1Up, switch1Down,
|
||||
onSwitch1UpTap, onSwitch1DownTap),
|
||||
_buildSwitchColumn(
|
||||
switchUp: switch1Up,
|
||||
switchDown: switch1Down,
|
||||
onUpTap: onSwitch1UpTap,
|
||||
onDownTap: onSwitch1DownTap,
|
||||
titleDown: switch3Title!,
|
||||
titleUp: switch1Title!),
|
||||
_buildDivider(),
|
||||
// Switch 2
|
||||
_buildSwitchColumn(switch2Up, switch2Down,
|
||||
onSwitch2UpTap, onSwitch2DownTap),
|
||||
_buildSwitchColumn(
|
||||
switchUp: switch2Up,
|
||||
switchDown: switch2Down,
|
||||
onDownTap: onSwitch2UpTap,
|
||||
onUpTap: onSwitch2DownTap,
|
||||
titleDown: switch4Title!,
|
||||
titleUp: switch2Title!),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -92,33 +112,49 @@ class SwitchsCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSwitchColumn(
|
||||
String switchUp,
|
||||
String switchDown,
|
||||
VoidCallback onUpTap,
|
||||
VoidCallback onDownTap,
|
||||
) {
|
||||
Widget _buildSwitchColumn({
|
||||
String switchUp = '',
|
||||
String titleUp = '',
|
||||
String titleDown = '',
|
||||
String switchDown = '',
|
||||
VoidCallback? onUpTap,
|
||||
VoidCallback? onDownTap,
|
||||
}) {
|
||||
return Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 30, bottom: 30),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: onUpTap,
|
||||
child: Container(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: SvgPicture.asset(switchUp),
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: onUpTap,
|
||||
child: Container(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: SvgPicture.asset(switchUp),
|
||||
),
|
||||
),
|
||||
BodySmall(
|
||||
text: titleUp,
|
||||
)
|
||||
],
|
||||
),
|
||||
InkWell(
|
||||
onTap: onDownTap,
|
||||
child: Container(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: SvgPicture.asset(switchDown),
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: onDownTap,
|
||||
child: Container(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: SvgPicture.asset(switchDown),
|
||||
),
|
||||
),
|
||||
BodySmall(
|
||||
text: titleDown,
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -77,18 +77,10 @@ class FourSceneScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
FourSwitchsCard(
|
||||
title1: _bloc.fourScene.isNotEmpty
|
||||
? _bloc.fourScene[0].scene.name
|
||||
: '',
|
||||
title2: _bloc.fourScene.length > 1
|
||||
? _bloc.fourScene[0].scene.name
|
||||
: '',
|
||||
title3: _bloc.fourScene.length > 2
|
||||
? _bloc.fourScene[0].scene.name
|
||||
: '',
|
||||
title4: _bloc.fourScene.length > 3
|
||||
? _bloc.fourScene[0].scene.name
|
||||
: '',
|
||||
title1: model.scene_1,
|
||||
title2: model.scene_2,
|
||||
title3: model.scene_3,
|
||||
title4: model.scene_4,
|
||||
switch1:
|
||||
_bloc.deviceStatus.switch_backlight == true
|
||||
? Assets.switchOn
|
||||
@ -163,14 +155,20 @@ class FourSceneScreen extends StatelessWidget {
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return FourSelectSwitchDialog(
|
||||
switch1Title: model.scene_1,
|
||||
switch2Title: model.scene_2,
|
||||
switch3Title: model.scene_3,
|
||||
switch4Title: model.scene_4,
|
||||
cancelTab: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
confirmTab: () {
|
||||
confirmTab: (switchSelected) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
FourSelectSceneFourPage()),
|
||||
FourSelectSceneFourPage(
|
||||
switchSelected: switchSelected,
|
||||
deviceId:device!.uuid)),
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -219,3 +217,6 @@ class FourSceneScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//MohaM&&&uba1
|
@ -17,7 +17,9 @@ import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class FourSelectSceneFourPage extends StatelessWidget {
|
||||
FourSelectSceneFourPage({super.key});
|
||||
final String? switchSelected;
|
||||
final String? deviceId;
|
||||
FourSelectSceneFourPage({super.key, this.switchSelected, this.deviceId});
|
||||
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final int? selectedSwitchIndex = 0;
|
||||
@ -26,12 +28,13 @@ class FourSelectSceneFourPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => FourSceneBloc(fourSceneId: '')
|
||||
create: (context) => FourSceneBloc(fourSceneId: deviceId!)
|
||||
..add(LoadScenes(
|
||||
unit: spaces!.first,
|
||||
unitId: spaces!.first.id,
|
||||
showInDevice: false,
|
||||
)),
|
||||
))
|
||||
..add(GetSceneBySwitchName(switchName: switchSelected)),
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensorBloc = BlocProvider.of<FourSceneBloc>(context);
|
||||
@ -57,8 +60,10 @@ class FourSelectSceneFourPage extends StatelessWidget {
|
||||
return GestureDetector(
|
||||
onTap: canSave
|
||||
? () {
|
||||
print('object');
|
||||
// context.read<FourSceneBloc>().add(SaveSelectionEvent());
|
||||
context.read<FourSceneBloc>().add(AssignDeviceScene(
|
||||
sceneUuid: sensorBloc.selectedSceneId,
|
||||
switchName: switchSelected,
|
||||
unit: spaces!.first));
|
||||
}
|
||||
: null,
|
||||
child: BodyMedium(
|
||||
@ -127,7 +132,6 @@ class FourSelectSceneFourPage extends StatelessWidget {
|
||||
// Scene grid builder
|
||||
Widget _buildSceneGrid(FourSceneBloc sensorBloc) {
|
||||
final scenes = sensorBloc.filteredScenes;
|
||||
|
||||
return GridView.builder(
|
||||
itemCount: scenes.length + 1,
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
@ -137,6 +141,7 @@ class FourSelectSceneFourPage extends StatelessWidget {
|
||||
mainAxisExtent: 120,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
// sensorBloc.sceneId;
|
||||
if (index == scenes.length) {
|
||||
return InkWell(
|
||||
onTap: () => Navigator.pushNamed(
|
||||
@ -154,7 +159,7 @@ class FourSelectSceneFourPage extends StatelessWidget {
|
||||
final scene = scenes[index];
|
||||
return SceneItem(
|
||||
id: scene.id,
|
||||
value: sensorBloc.selectedSceneId == scene.id,
|
||||
value: (sensorBloc.selectedSceneId == scene.id),
|
||||
disablePlayButton: false,
|
||||
onChanged: (isSelected) {
|
||||
sensorBloc.selectedSceneId = isSelected ? scene.id : 'null';
|
||||
|
@ -6,20 +6,28 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class FourSelectSwitchDialog extends StatefulWidget {
|
||||
final Function()? cancelTab;
|
||||
final Function()? confirmTab;
|
||||
final Function(String)? confirmTab;
|
||||
|
||||
const FourSelectSwitchDialog({
|
||||
super.key,
|
||||
required this.cancelTab,
|
||||
required this.confirmTab,
|
||||
});
|
||||
final String switch1Title;
|
||||
final String switch2Title;
|
||||
final String switch3Title;
|
||||
final String switch4Title;
|
||||
|
||||
const FourSelectSwitchDialog(
|
||||
{super.key,
|
||||
required this.cancelTab,
|
||||
required this.confirmTab,
|
||||
required this.switch1Title,
|
||||
required this.switch2Title,
|
||||
required this.switch3Title,
|
||||
required this.switch4Title});
|
||||
|
||||
@override
|
||||
State<FourSelectSwitchDialog> createState() => _FourSelectSwitchDialogState();
|
||||
}
|
||||
|
||||
class _FourSelectSwitchDialogState extends State<FourSelectSwitchDialog> {
|
||||
int? selectedSwitchIndex = 0; // State variable to track selected switch
|
||||
String selectedSwitchName = ''; // State variable to track selected switch
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -44,33 +52,34 @@ class _FourSelectSwitchDialogState extends State<FourSelectSwitchDialog> {
|
||||
Row(
|
||||
children: [
|
||||
SwitchsCard(
|
||||
switch1Down: selectedSwitchIndex == -1
|
||||
switch1Title: widget.switch1Title,
|
||||
switch2Title: widget.switch2Title,
|
||||
switch3Title: widget.switch3Title,
|
||||
switch4Title: widget.switch4Title,
|
||||
switch1Down: selectedSwitchName == 'scene_3'
|
||||
? Assets.removeSceneIcon
|
||||
: Assets.addSwitchIcon,
|
||||
switch1Up: selectedSwitchIndex == 1
|
||||
switch1Up: selectedSwitchName == 'scene_1'
|
||||
? Assets.removeSceneIcon
|
||||
: Assets.addSwitchIcon,
|
||||
switch2Down: selectedSwitchIndex == -2
|
||||
switch2Down: selectedSwitchName == 'scene_4'
|
||||
? Assets.removeSceneIcon
|
||||
: Assets.addSwitchIcon,
|
||||
switch2Up: selectedSwitchIndex == 2
|
||||
switch2Up: selectedSwitchName == 'scene_2'
|
||||
? Assets.removeSceneIcon
|
||||
: Assets.addSwitchIcon,
|
||||
|
||||
onSwitch1UpTap: () {
|
||||
setState(() => selectedSwitchIndex = 1);
|
||||
setState(() => selectedSwitchName = 'scene_1');
|
||||
},
|
||||
onSwitch1DownTap: () {
|
||||
setState(() => selectedSwitchIndex = -1);
|
||||
setState(() => selectedSwitchName = 'scene_3');
|
||||
},
|
||||
onSwitch2UpTap: () {
|
||||
setState(() => selectedSwitchIndex = 2);
|
||||
setState(() => selectedSwitchName = 'scene_4');
|
||||
},
|
||||
onSwitch2DownTap: () {
|
||||
setState(() => selectedSwitchIndex = -2);
|
||||
|
||||
setState(() => selectedSwitchName = 'scene_2');
|
||||
},
|
||||
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -118,14 +127,16 @@ class _FourSelectSwitchDialogState extends State<FourSelectSwitchDialog> {
|
||||
top: BorderSide(color: ColorsManager.textGray, width: 1.0),
|
||||
)),
|
||||
child: InkWell(
|
||||
onTap: selectedSwitchIndex == 0 ? () {} : widget.confirmTab,
|
||||
onTap: selectedSwitchName == ''
|
||||
? () {}
|
||||
: () => widget.confirmTab!(selectedSwitchName),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(15),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Next',
|
||||
style: TextStyle(
|
||||
color: selectedSwitchIndex == 0
|
||||
color: selectedSwitchName == ''
|
||||
? ColorsManager.textPrimaryColor
|
||||
.withOpacity(0.6)
|
||||
: ColorsManager.primaryColor,
|
||||
|
@ -213,5 +213,8 @@ abstract class ApiEndpoints {
|
||||
'/device/report-logs/{deviceUuid}?code={code}&startTime={startTime}&endTime={endTime}';
|
||||
static const String controlBatch = '/device/control/batch';
|
||||
static const String statusBatch = '/device/status/batch';
|
||||
static const String getFourScene = '/device/four-scene/{deviceUuid}';
|
||||
static const String fourScene = '/device/{deviceUuid}/scenes';
|
||||
|
||||
static const String fourSceneByName =
|
||||
'/device/{deviceUuid}/scenes?switchName={switchName}';
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ class DevicesAPI {
|
||||
|
||||
static Future getFourSceneInfo(String deviceId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getFourScene.replaceAll('{deviceUuid}', deviceId),
|
||||
path: ApiEndpoints.fourScene.replaceAll('{deviceUuid}', deviceId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
@ -148,6 +148,42 @@ class DevicesAPI {
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future getSceneBySwitchName(
|
||||
{String? deviceId, String? switchName}) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.fourSceneByName
|
||||
.replaceAll('{deviceUuid}', deviceId!)
|
||||
.replaceAll('{switchName}', switchName!),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future postFourSceneInfo({
|
||||
String? switchName,
|
||||
String? sceneUuid,
|
||||
String? deviceId,
|
||||
String? spaceUuid,
|
||||
}) async {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.fourScene.replaceAll('{deviceUuid}', deviceId!),
|
||||
body: jsonEncode(
|
||||
{
|
||||
"switchName": switchName,
|
||||
"sceneUuid": sceneUuid,
|
||||
"spaceUuid": spaceUuid
|
||||
},
|
||||
),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
print('postFourSceneInfo=$json');
|
||||
return json;
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future getDeviceInfo(String deviceId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
|
||||
|
Reference in New Issue
Block a user