mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
4scene
This commit is contained in:
@ -4,10 +4,12 @@ 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';
|
||||
import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_report_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/four_scene_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/four_scene_question_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/four_scene_switch_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/group_devices_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/scene_switch_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
@ -43,6 +45,8 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
on<RemoveDeviceFromGroup>(_removeDeviceFromGroup);
|
||||
on<FourSceneInitialQuestion>(_onFourSceneInitial);
|
||||
on<FetchDeviceScene>(_fetchDeviceScene);
|
||||
on<ControlDeviceScene>(_controlDevice);
|
||||
on<FourSceneSwitchInitial>(_fetchFourSceneSwitches);
|
||||
}
|
||||
|
||||
final TextEditingController nameController =
|
||||
@ -55,7 +59,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
static String deviceName = '';
|
||||
static String selectedRoomId = '';
|
||||
|
||||
FourSceneModel deviceStatus = FourSceneModel(
|
||||
FourSceneModelState deviceStatus = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
@ -96,28 +100,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
),
|
||||
);
|
||||
|
||||
// void changeDeviceName(
|
||||
// SaveNameEvent event, Emitter<FourSceneState> emit) async {
|
||||
// emit(FourSceneLoadingState());
|
||||
// try {
|
||||
// var response = await DevicesAPI.putDeviceName(
|
||||
// deviceId: fourSceneId, deviceName: event.deviceName!);
|
||||
// List<StatusModel> statusModelList = [];
|
||||
// for (var status in response['status']) {
|
||||
// statusModelList.add(StatusModel.fromJson(status));
|
||||
// }
|
||||
// deviceStatus = FourSceneModel.fromJson(
|
||||
// statusModelList,
|
||||
// );
|
||||
// emit(UpdateState(sensor: deviceStatus));
|
||||
// Future.delayed(const Duration(milliseconds: 500));
|
||||
// // _listenToChanges();
|
||||
// } catch (e) {
|
||||
// emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> saveName(
|
||||
SaveNameEvent event, Emitter<FourSceneState> emit) async {
|
||||
if (_validateInputs()) return;
|
||||
@ -137,6 +119,34 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
List<FourSceneSwitchModel> fourScene = [];
|
||||
|
||||
void _fetchFourSceneSwitches(
|
||||
FourSceneSwitchInitial event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
List<dynamic> response = await DevicesAPI.getFourSceneInfo(fourSceneId);
|
||||
fourScene =
|
||||
response.map((item) => FourSceneSwitchModel.fromJson(item)).toList();
|
||||
print('Fetched response: $fourScene');
|
||||
_rankFourSceneSwitches();
|
||||
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} catch (e) {
|
||||
print('Error in _fetchFourSceneSwitches: $e');
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
FourSceneInitial event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
@ -146,10 +156,10 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus = FourSceneModel.fromJson(
|
||||
deviceStatus = FourSceneModelState.fromJson(
|
||||
statusModelList,
|
||||
);
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
// _listenToChanges();
|
||||
} catch (e) {
|
||||
@ -167,10 +177,10 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus = FourSceneModel.fromJson(
|
||||
deviceStatus = FourSceneModelState.fromJson(
|
||||
statusModelList,
|
||||
);
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
// _listenToChanges();
|
||||
} catch (e) {
|
||||
@ -179,6 +189,27 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _controlDevice(
|
||||
ControlDeviceScene event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
deviceStatus.switch_backlight = !event.backLight!;
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: fourSceneId,
|
||||
code: 'switch_backlight',
|
||||
value: !event.backLight!),
|
||||
fourSceneId);
|
||||
|
||||
if (!response['success']) {
|
||||
// add(InitialEvent(groupScreen: oneTouchGroup));
|
||||
}
|
||||
} catch (_) {
|
||||
// add(InitialEvent(groupScreen: oneTouchGroup));
|
||||
}
|
||||
}
|
||||
|
||||
Future fetchDeviceData(
|
||||
FourSceneInitialInfo event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
@ -213,10 +244,10 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
|
||||
void _toggleNotification(
|
||||
ToggleNotificationEvent event, Emitter<FourSceneState> emit) async {
|
||||
emit(LoadingNewSate(sosSensor: deviceStatus));
|
||||
emit(LoadingNewSate(device: deviceStatus));
|
||||
try {
|
||||
closingReminder = event.isClosingEnabled;
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
// API call to update the state, if necessary
|
||||
// await DevicesAPI.controlDevice(
|
||||
// DeviceControlModel(
|
||||
@ -249,7 +280,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
code: 'sossensor_state',
|
||||
);
|
||||
recordGroups = response;
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
String errorMessage = errorData['message'];
|
||||
@ -304,7 +335,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
emit(FourSceneLoadingState());
|
||||
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||
event.unit.community.uuid, event.unit.id);
|
||||
print(roomsList);
|
||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||
} catch (e) {
|
||||
emit(const FourSceneFailedState(errorMessage: 'Something went wrong'));
|
||||
@ -313,11 +343,26 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
|
||||
bool switchStatus = true;
|
||||
void changeSwitchStatus(
|
||||
ChangeSwitchStatusEvent event, Emitter<FourSceneState> emit) {
|
||||
Future<void> changeSwitchStatus(
|
||||
ChangeSwitchStatusEvent event, Emitter<FourSceneState> emit) async {
|
||||
try {
|
||||
emit(FourSceneLoadingState());
|
||||
switchStatus = deviceStatus.switch_backlight;
|
||||
switchStatus = !switchStatus;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: fourSceneId,
|
||||
code: 'switch_backlight',
|
||||
value: switchStatus),
|
||||
fourSceneId);
|
||||
deviceStatus.switch_backlight = switchStatus;
|
||||
if (!response['success']) {
|
||||
add(const FourSceneInitial());
|
||||
}
|
||||
emit(ChangeSwitchState(isEnable: switchStatus));
|
||||
} catch (_) {
|
||||
add(const FourSceneInitial());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onLoadScenes(
|
||||
@ -385,19 +430,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
dec: 'Syncroom', icon: Assets.addDevicesIcon, name: '6 Scene Switch')
|
||||
];
|
||||
|
||||
// @override
|
||||
// Stream<FourSceneState> mapEventToState(FourSceneEvent event) async* {
|
||||
// if (event is AddDeviceToGroup) {
|
||||
// devices.remove(event.device);
|
||||
// groupDevices.add(event.device);
|
||||
// yield UpdateStateList(groupDevices: groupDevices, devices: devices);
|
||||
// } else if (event is RemoveDeviceFromGroup) {
|
||||
// groupDevices.remove(event.device);
|
||||
// devices.add(event.device);
|
||||
// yield UpdateStateList(groupDevices: groupDevices, devices: devices);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Handler for AddDeviceToGroup
|
||||
void _addDeviceToGroup(AddDeviceToGroup event, Emitter<FourSceneState> emit) {
|
||||
devices.remove(event.device);
|
||||
@ -466,4 +498,9 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
String scene1 = 'scene_1';
|
||||
String scene2 = 'scene_2';
|
||||
String scene3 = 'scene_3';
|
||||
String scene4 = 'scene_4';
|
||||
}
|
||||
|
@ -25,7 +25,9 @@ class FourSceneSwitch extends FourSceneEvent {
|
||||
|
||||
class FourSceneUpdated extends FourSceneEvent {}
|
||||
|
||||
class FourSceneInitialInfo extends FourSceneEvent {}
|
||||
class FourSceneInitialInfo extends FourSceneEvent {
|
||||
const FourSceneInitialInfo();
|
||||
}
|
||||
|
||||
class FourSceneInitial extends FourSceneEvent {
|
||||
const FourSceneInitial();
|
||||
@ -200,6 +202,13 @@ class AssignRoomEvent extends FourSceneEvent {
|
||||
];
|
||||
}
|
||||
|
||||
class FetchDeviceScene extends FourSceneEvent {
|
||||
const FetchDeviceScene();
|
||||
class FetchDeviceScene extends FourSceneEvent {}
|
||||
|
||||
class ControlDeviceScene extends FourSceneEvent {
|
||||
final bool? backLight;
|
||||
const ControlDeviceScene({this.backLight});
|
||||
}
|
||||
|
||||
class FourSceneSwitchInitial extends FourSceneEvent {
|
||||
const FourSceneSwitchInitial();
|
||||
}
|
||||
|
@ -36,19 +36,19 @@ class FourSceneFailedState extends FourSceneState {
|
||||
}
|
||||
|
||||
class UpdateState extends FourSceneState {
|
||||
final FourSceneModel sensor;
|
||||
const UpdateState({required this.sensor});
|
||||
final FourSceneModelState device;
|
||||
const UpdateState({required this.device});
|
||||
|
||||
@override
|
||||
List<Object> get props => [sensor];
|
||||
List<Object> get props => [device];
|
||||
}
|
||||
|
||||
class LoadingNewSate extends FourSceneState {
|
||||
final FourSceneModel sosSensor;
|
||||
const LoadingNewSate({required this.sosSensor});
|
||||
final FourSceneModelState device;
|
||||
const LoadingNewSate({required this.device});
|
||||
|
||||
@override
|
||||
List<Object> get props => [sosSensor];
|
||||
List<Object> get props => [device];
|
||||
}
|
||||
|
||||
class NameEditingState extends FourSceneState {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
|
||||
class FourSceneModel {
|
||||
class FourSceneModelState {
|
||||
dynamic scene_1;
|
||||
dynamic scene_2;
|
||||
dynamic scene_3;
|
||||
@ -8,7 +8,7 @@ class FourSceneModel {
|
||||
dynamic scene_id_group_id;
|
||||
dynamic switch_backlight;
|
||||
|
||||
FourSceneModel({
|
||||
FourSceneModelState({
|
||||
required this.scene_1,
|
||||
required this.scene_2,
|
||||
required this.scene_3,
|
||||
@ -17,7 +17,7 @@ class FourSceneModel {
|
||||
required this.switch_backlight,
|
||||
});
|
||||
|
||||
factory FourSceneModel.fromJson(List<StatusModel> jsonList) {
|
||||
factory FourSceneModelState.fromJson(List<StatusModel> jsonList) {
|
||||
late dynamic _scene_1;
|
||||
late dynamic _scene_2;
|
||||
late dynamic _scene_3;
|
||||
@ -40,7 +40,7 @@ class FourSceneModel {
|
||||
_switch_backlight = jsonList[i].value ?? false;
|
||||
}
|
||||
}
|
||||
return FourSceneModel(
|
||||
return FourSceneModelState(
|
||||
scene_1: _scene_1,
|
||||
scene_2: _scene_2,
|
||||
scene_3: _scene_3,
|
||||
|
85
lib/features/devices/model/four_scene_switch_model.dart
Normal file
85
lib/features/devices/model/four_scene_switch_model.dart
Normal file
@ -0,0 +1,85 @@
|
||||
class FourSceneSwitchModel {
|
||||
final String switchName;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
final String deviceUuid;
|
||||
final Scene scene;
|
||||
|
||||
FourSceneSwitchModel({
|
||||
required this.switchName,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
required this.deviceUuid,
|
||||
required this.scene,
|
||||
});
|
||||
|
||||
factory FourSceneSwitchModel.fromJson(Map<String, dynamic> json) {
|
||||
return FourSceneSwitchModel(
|
||||
switchName: json['switchName'],
|
||||
createdAt: DateTime.parse(json['createdAt']),
|
||||
updatedAt: DateTime.parse(json['updatedAt']),
|
||||
deviceUuid: json['deviceUuid'],
|
||||
scene: Scene.fromJson(json['scene']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Scene {
|
||||
final String uuid;
|
||||
final String sceneTuyaId;
|
||||
final String name;
|
||||
final String status;
|
||||
final String icon;
|
||||
final String iconUuid;
|
||||
final bool showInHome;
|
||||
final String type;
|
||||
final List<Action> actions;
|
||||
|
||||
Scene({
|
||||
required this.uuid,
|
||||
required this.sceneTuyaId,
|
||||
required this.name,
|
||||
required this.status,
|
||||
required this.icon,
|
||||
required this.iconUuid,
|
||||
required this.showInHome,
|
||||
required this.type,
|
||||
required this.actions,
|
||||
});
|
||||
|
||||
factory Scene.fromJson(Map<String, dynamic> json) {
|
||||
return Scene(
|
||||
uuid: json['uuid'],
|
||||
sceneTuyaId: json['sceneTuyaId'],
|
||||
name: json['name'],
|
||||
status: json['status'],
|
||||
icon: json['icon'],
|
||||
iconUuid: json['iconUuid'],
|
||||
showInHome: json['showInHome'],
|
||||
type: json['type'],
|
||||
actions: (json['actions'] as List)
|
||||
.map((action) => Action.fromJson(action))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Action {
|
||||
final String actionExecutor;
|
||||
final String entityId;
|
||||
final Map<String, dynamic> executorProperty;
|
||||
|
||||
Action({
|
||||
required this.actionExecutor,
|
||||
required this.entityId,
|
||||
required this.executorProperty,
|
||||
});
|
||||
|
||||
factory Action.fromJson(Map<String, dynamic> json) {
|
||||
return Action(
|
||||
actionExecutor: json['actionExecutor'],
|
||||
entityId: json['entityId'],
|
||||
executorProperty: json['executorProperty'],
|
||||
);
|
||||
}
|
||||
}
|
@ -42,11 +42,12 @@ class FourSceneScreen extends StatelessWidget {
|
||||
child: BlocProvider(
|
||||
create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '')
|
||||
..add(const FourSceneInitial())
|
||||
..add(FourSceneInitialInfo()),
|
||||
..add(const FourSceneInitialInfo())
|
||||
..add(const FourSceneSwitchInitial()),
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModel model = FourSceneModel(
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModelState model = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
@ -54,9 +55,9 @@ class FourSceneScreen extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is FourSceneLoadingState
|
||||
? const Center(
|
||||
@ -67,7 +68,7 @@ class FourSceneScreen extends StatelessWidget {
|
||||
)
|
||||
: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
sensor.add(const FourSceneInitial());
|
||||
_bloc.add(const FourSceneInitial());
|
||||
},
|
||||
child: ListView(
|
||||
children: [
|
||||
@ -76,29 +77,45 @@ class FourSceneScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
FourSwitchsCard(
|
||||
switch1Down: sensor.switchStatus == true
|
||||
title1: _bloc.fourScene.isNotEmpty
|
||||
? _bloc.fourScene[0].switchName
|
||||
: 'title1',
|
||||
title2: _bloc.fourScene.length > 1
|
||||
? _bloc.fourScene[1].switchName
|
||||
: 'title2',
|
||||
title3: _bloc.fourScene.length > 2
|
||||
? _bloc.fourScene[2].switchName
|
||||
: 'title3',
|
||||
title4: _bloc.fourScene.length > 3
|
||||
? _bloc.fourScene[3].switchName
|
||||
: 'title4',
|
||||
switch1:
|
||||
_bloc.deviceStatus.switch_backlight == true
|
||||
? Assets.switchOn
|
||||
: Assets.switchOff,
|
||||
switch1Up: sensor.switchStatus == true
|
||||
switch2:
|
||||
_bloc.deviceStatus.switch_backlight == true
|
||||
? Assets.switchOn
|
||||
: Assets.switchOff,
|
||||
switch2Down: sensor.switchStatus == true
|
||||
switch3:
|
||||
_bloc.deviceStatus.switch_backlight == true
|
||||
? Assets.switchOn
|
||||
: Assets.switchOff,
|
||||
switch2Up: sensor.switchStatus == true
|
||||
switch4:
|
||||
_bloc.deviceStatus.switch_backlight == true
|
||||
? Assets.switchOn
|
||||
: Assets.switchOff,
|
||||
onSwitch1UpTap: () {
|
||||
debugPrint("Switch 1 Up tapped");
|
||||
},
|
||||
onSwitch1DownTap: () {
|
||||
debugPrint("Switch 1 Down tapped");
|
||||
},
|
||||
onSwitch2UpTap: () {
|
||||
debugPrint("Switch 2 Up tapped");
|
||||
},
|
||||
onSwitch2DownTap: () {
|
||||
debugPrint("Switch 2 Down tapped");
|
||||
onSwitch3DownTap: () {
|
||||
debugPrint("onSwitch3DownTap");
|
||||
},
|
||||
onSwitch4DownTap: () {
|
||||
debugPrint("onSwitch4DownTap");
|
||||
},
|
||||
),
|
||||
Flexible(
|
||||
@ -107,7 +124,7 @@ class FourSceneScreen extends StatelessWidget {
|
||||
Expanded(
|
||||
child: DefaultContainer(
|
||||
onTap: () {
|
||||
sensor.add(ChangeSwitchStatusEvent());
|
||||
_bloc.add(ChangeSwitchStatusEvent());
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
|
@ -29,7 +29,7 @@ class FourSceneCreateGroup extends StatelessWidget {
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModel model = FourSceneModel(
|
||||
FourSceneModelState model = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
@ -37,9 +37,9 @@ class FourSceneCreateGroup extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is LoadingNewSate
|
||||
? const Center(
|
||||
|
@ -29,7 +29,7 @@ class FourSceneInfoPage extends StatelessWidget {
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModel model = FourSceneModel(
|
||||
FourSceneModelState model = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
@ -37,9 +37,9 @@ class FourSceneInfoPage extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is FourSceneLoadingState
|
||||
? const Center(
|
||||
|
@ -33,11 +33,11 @@ class FourSceneProfilePage extends StatelessWidget {
|
||||
child: BlocProvider(
|
||||
create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '')
|
||||
..add(const FourSceneInitial())
|
||||
..add(FourSceneInitialInfo()),
|
||||
..add(const FourSceneInitialInfo()),
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModel model = FourSceneModel(
|
||||
FourSceneModelState model = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
@ -45,9 +45,9 @@ class FourSceneProfilePage extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is FourSceneLoadingState
|
||||
? const Center(
|
||||
|
@ -39,7 +39,7 @@ class FourSceneSettings extends StatelessWidget {
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModel model = FourSceneModel(
|
||||
FourSceneModelState model = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
@ -47,9 +47,9 @@ class FourSceneSettings extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is FourSceneLoadingState
|
||||
? const Center(
|
||||
|
@ -34,7 +34,7 @@ class LocationFourScenePage extends StatelessWidget {
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModel model = FourSceneModel(
|
||||
FourSceneModelState model = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
|
@ -29,7 +29,7 @@ class QuestionPageFourScene extends StatelessWidget {
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModel model = FourSceneModel(
|
||||
FourSceneModelState model = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
@ -37,9 +37,9 @@ class QuestionPageFourScene extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is FourSceneLoadingState
|
||||
? const Center(
|
||||
|
@ -25,7 +25,7 @@ class ShareFourScenePage extends StatelessWidget {
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModel model = FourSceneModel(
|
||||
FourSceneModelState model = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
@ -33,9 +33,9 @@ class ShareFourScenePage extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is LoadingNewSate
|
||||
? const Center(
|
||||
|
@ -68,6 +68,7 @@ class _FourSelectSwitchDialogState extends State<FourSelectSwitchDialog> {
|
||||
},
|
||||
onSwitch2DownTap: () {
|
||||
setState(() => selectedSwitchIndex = -2);
|
||||
|
||||
},
|
||||
|
||||
),
|
||||
|
@ -3,25 +3,35 @@ import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class FourSwitchsCard extends StatelessWidget {
|
||||
final String switch1Up;
|
||||
final String switch1Down;
|
||||
final String switch2Up;
|
||||
final String switch2Down;
|
||||
final String switch1;
|
||||
final String title1;
|
||||
final String switch3;
|
||||
final String title3;
|
||||
|
||||
final String switch2;
|
||||
final String title2;
|
||||
|
||||
final String switch4;
|
||||
final String title4;
|
||||
|
||||
final VoidCallback onSwitch1UpTap;
|
||||
final VoidCallback onSwitch1DownTap;
|
||||
final VoidCallback onSwitch4DownTap;
|
||||
final VoidCallback onSwitch2UpTap;
|
||||
final VoidCallback onSwitch2DownTap;
|
||||
final VoidCallback onSwitch3DownTap;
|
||||
|
||||
FourSwitchsCard({
|
||||
required this.switch1Down,
|
||||
required this.switch1Up,
|
||||
required this.switch2Down,
|
||||
required this.switch2Up,
|
||||
required this.title1,
|
||||
required this.title2,
|
||||
required this.title3,
|
||||
required this.title4,
|
||||
required this.switch3,
|
||||
required this.switch1,
|
||||
required this.switch4,
|
||||
required this.switch2,
|
||||
required this.onSwitch1UpTap,
|
||||
required this.onSwitch1DownTap,
|
||||
required this.onSwitch3DownTap,
|
||||
required this.onSwitch2UpTap,
|
||||
required this.onSwitch2DownTap,
|
||||
required this.onSwitch4DownTap,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -73,9 +83,21 @@ class FourSwitchsCard extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildSwitchColumn(switch1Up, switch1Down, onSwitch1UpTap, onSwitch1DownTap),
|
||||
_buildSwitchColumn(
|
||||
switchUp: switch1,
|
||||
switchDown: switch3,
|
||||
onUpTap: onSwitch1UpTap,
|
||||
onDownTap: onSwitch3DownTap,
|
||||
titleDown: title3,
|
||||
titleUp: title1),
|
||||
_buildDivider(),
|
||||
_buildSwitchColumn(switch2Up, switch2Down, onSwitch2UpTap, onSwitch2DownTap),
|
||||
_buildSwitchColumn(
|
||||
titleDown: title4,
|
||||
titleUp: title2,
|
||||
switchUp: switch2,
|
||||
switchDown: switch4,
|
||||
onUpTap: onSwitch2UpTap,
|
||||
onDownTap: onSwitch4DownTap),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -88,17 +110,21 @@ class FourSwitchsCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSwitchColumn(
|
||||
String switchUp,
|
||||
String switchDown,
|
||||
VoidCallback onUpTap,
|
||||
VoidCallback onDownTap,
|
||||
) {
|
||||
Widget _buildSwitchColumn({
|
||||
String switchUp = '',
|
||||
String switchDown = '',
|
||||
String titleUp = '',
|
||||
String titleDown = '',
|
||||
VoidCallback? onUpTap,
|
||||
VoidCallback? onDownTap,
|
||||
}) {
|
||||
return Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 30, bottom: 30),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: onUpTap,
|
||||
@ -108,6 +134,11 @@ class FourSwitchsCard extends StatelessWidget {
|
||||
child: SvgPicture.asset(switchUp),
|
||||
),
|
||||
),
|
||||
Text(titleUp)
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: onDownTap,
|
||||
child: Container(
|
||||
@ -116,6 +147,9 @@ class FourSwitchsCard extends StatelessWidget {
|
||||
child: SvgPicture.asset(switchDown),
|
||||
),
|
||||
),
|
||||
Text(titleDown)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -213,4 +213,5 @@ 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}';
|
||||
}
|
||||
|
@ -138,12 +138,21 @@ class DevicesAPI {
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future getFourSceneInfo(String deviceId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getFourScene.replaceAll('{deviceUuid}', deviceId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future getDeviceInfo(String deviceId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
print('object-=-=-$json');
|
||||
return json;
|
||||
});
|
||||
return response;
|
||||
|
Reference in New Issue
Block a user