This commit is contained in:
mohammad
2024-11-19 15:45:28 +03:00
parent 1be6d71e89
commit 777bd549ca
17 changed files with 334 additions and 141 deletions
@@ -4,10 +4,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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_event.dart';
import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_state.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_model.dart';
import 'package:syncrow_app/features/devices/model/device_report_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_model.dart';
import 'package:syncrow_app/features/devices/model/four_scene_question_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/group_devices_model.dart';
import 'package:syncrow_app/features/devices/model/scene_switch_model.dart'; import 'package:syncrow_app/features/devices/model/scene_switch_model.dart';
import 'package:syncrow_app/features/devices/model/status_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<RemoveDeviceFromGroup>(_removeDeviceFromGroup);
on<FourSceneInitialQuestion>(_onFourSceneInitial); on<FourSceneInitialQuestion>(_onFourSceneInitial);
on<FetchDeviceScene>(_fetchDeviceScene); on<FetchDeviceScene>(_fetchDeviceScene);
on<ControlDeviceScene>(_controlDevice);
on<FourSceneSwitchInitial>(_fetchFourSceneSwitches);
} }
final TextEditingController nameController = final TextEditingController nameController =
@@ -55,7 +59,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
static String deviceName = ''; static String deviceName = '';
static String selectedRoomId = ''; static String selectedRoomId = '';
FourSceneModel deviceStatus = FourSceneModel( FourSceneModelState deviceStatus = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', 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( Future<void> saveName(
SaveNameEvent event, Emitter<FourSceneState> emit) async { SaveNameEvent event, Emitter<FourSceneState> emit) async {
if (_validateInputs()) return; 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( void _fetchStatus(
FourSceneInitial event, Emitter<FourSceneState> emit) async { FourSceneInitial event, Emitter<FourSceneState> emit) async {
emit(FourSceneLoadingState()); emit(FourSceneLoadingState());
@@ -146,10 +156,10 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
for (var status in response['status']) { for (var status in response['status']) {
statusModelList.add(StatusModel.fromJson(status)); statusModelList.add(StatusModel.fromJson(status));
} }
deviceStatus = FourSceneModel.fromJson( deviceStatus = FourSceneModelState.fromJson(
statusModelList, statusModelList,
); );
emit(UpdateState(sensor: deviceStatus)); emit(UpdateState(device: deviceStatus));
Future.delayed(const Duration(milliseconds: 500)); Future.delayed(const Duration(milliseconds: 500));
// _listenToChanges(); // _listenToChanges();
} catch (e) { } catch (e) {
@@ -167,10 +177,10 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
for (var status in response['status']) { for (var status in response['status']) {
statusModelList.add(StatusModel.fromJson(status)); statusModelList.add(StatusModel.fromJson(status));
} }
deviceStatus = FourSceneModel.fromJson( deviceStatus = FourSceneModelState.fromJson(
statusModelList, statusModelList,
); );
emit(UpdateState(sensor: deviceStatus)); emit(UpdateState(device: deviceStatus));
Future.delayed(const Duration(milliseconds: 500)); Future.delayed(const Duration(milliseconds: 500));
// _listenToChanges(); // _listenToChanges();
} catch (e) { } 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( Future fetchDeviceData(
FourSceneInitialInfo event, Emitter<FourSceneState> emit) async { FourSceneInitialInfo event, Emitter<FourSceneState> emit) async {
emit(FourSceneLoadingState()); emit(FourSceneLoadingState());
@@ -213,10 +244,10 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
void _toggleNotification( void _toggleNotification(
ToggleNotificationEvent event, Emitter<FourSceneState> emit) async { ToggleNotificationEvent event, Emitter<FourSceneState> emit) async {
emit(LoadingNewSate(sosSensor: deviceStatus)); emit(LoadingNewSate(device: deviceStatus));
try { try {
closingReminder = event.isClosingEnabled; closingReminder = event.isClosingEnabled;
emit(UpdateState(sensor: deviceStatus)); emit(UpdateState(device: deviceStatus));
// API call to update the state, if necessary // API call to update the state, if necessary
// await DevicesAPI.controlDevice( // await DevicesAPI.controlDevice(
// DeviceControlModel( // DeviceControlModel(
@@ -249,7 +280,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
code: 'sossensor_state', code: 'sossensor_state',
); );
recordGroups = response; recordGroups = response;
emit(UpdateState(sensor: deviceStatus)); emit(UpdateState(device: deviceStatus));
} on DioException catch (e) { } on DioException catch (e) {
final errorData = e.response!.data; final errorData = e.response!.data;
String errorMessage = errorData['message']; String errorMessage = errorData['message'];
@@ -304,7 +335,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
emit(FourSceneLoadingState()); emit(FourSceneLoadingState());
roomsList = await SpacesAPI.getSubSpaceBySpaceId( roomsList = await SpacesAPI.getSubSpaceBySpaceId(
event.unit.community.uuid, event.unit.id); event.unit.community.uuid, event.unit.id);
print(roomsList);
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList)); emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
} catch (e) { } catch (e) {
emit(const FourSceneFailedState(errorMessage: 'Something went wrong')); emit(const FourSceneFailedState(errorMessage: 'Something went wrong'));
@@ -313,11 +343,26 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
} }
bool switchStatus = true; bool switchStatus = true;
void changeSwitchStatus( Future<void> changeSwitchStatus(
ChangeSwitchStatusEvent event, Emitter<FourSceneState> emit) { ChangeSwitchStatusEvent event, Emitter<FourSceneState> emit) async {
emit(FourSceneLoadingState()); try {
switchStatus = !switchStatus; emit(FourSceneLoadingState());
emit(ChangeSwitchState(isEnable: switchStatus)); 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( Future<void> _onLoadScenes(
@@ -385,19 +430,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
dec: 'Syncroom', icon: Assets.addDevicesIcon, name: '6 Scene Switch') 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 // Handler for AddDeviceToGroup
void _addDeviceToGroup(AddDeviceToGroup event, Emitter<FourSceneState> emit) { void _addDeviceToGroup(AddDeviceToGroup event, Emitter<FourSceneState> emit) {
devices.remove(event.device); devices.remove(event.device);
@@ -466,4 +498,9 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
return null; 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 FourSceneUpdated extends FourSceneEvent {}
class FourSceneInitialInfo extends FourSceneEvent {} class FourSceneInitialInfo extends FourSceneEvent {
const FourSceneInitialInfo();
}
class FourSceneInitial extends FourSceneEvent { class FourSceneInitial extends FourSceneEvent {
const FourSceneInitial(); const FourSceneInitial();
@@ -200,6 +202,13 @@ class AssignRoomEvent extends FourSceneEvent {
]; ];
} }
class FetchDeviceScene extends FourSceneEvent { class FetchDeviceScene extends FourSceneEvent {}
const FetchDeviceScene();
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 { class UpdateState extends FourSceneState {
final FourSceneModel sensor; final FourSceneModelState device;
const UpdateState({required this.sensor}); const UpdateState({required this.device});
@override @override
List<Object> get props => [sensor]; List<Object> get props => [device];
} }
class LoadingNewSate extends FourSceneState { class LoadingNewSate extends FourSceneState {
final FourSceneModel sosSensor; final FourSceneModelState device;
const LoadingNewSate({required this.sosSensor}); const LoadingNewSate({required this.device});
@override @override
List<Object> get props => [sosSensor]; List<Object> get props => [device];
} }
class NameEditingState extends FourSceneState { class NameEditingState extends FourSceneState {
@@ -1,6 +1,6 @@
import 'package:syncrow_app/features/devices/model/status_model.dart'; import 'package:syncrow_app/features/devices/model/status_model.dart';
class FourSceneModel { class FourSceneModelState {
dynamic scene_1; dynamic scene_1;
dynamic scene_2; dynamic scene_2;
dynamic scene_3; dynamic scene_3;
@@ -8,7 +8,7 @@ class FourSceneModel {
dynamic scene_id_group_id; dynamic scene_id_group_id;
dynamic switch_backlight; dynamic switch_backlight;
FourSceneModel({ FourSceneModelState({
required this.scene_1, required this.scene_1,
required this.scene_2, required this.scene_2,
required this.scene_3, required this.scene_3,
@@ -17,7 +17,7 @@ class FourSceneModel {
required this.switch_backlight, required this.switch_backlight,
}); });
factory FourSceneModel.fromJson(List<StatusModel> jsonList) { factory FourSceneModelState.fromJson(List<StatusModel> jsonList) {
late dynamic _scene_1; late dynamic _scene_1;
late dynamic _scene_2; late dynamic _scene_2;
late dynamic _scene_3; late dynamic _scene_3;
@@ -40,7 +40,7 @@ class FourSceneModel {
_switch_backlight = jsonList[i].value ?? false; _switch_backlight = jsonList[i].value ?? false;
} }
} }
return FourSceneModel( return FourSceneModelState(
scene_1: _scene_1, scene_1: _scene_1,
scene_2: _scene_2, scene_2: _scene_2,
scene_3: _scene_3, scene_3: _scene_3,
@@ -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( child: BlocProvider(
create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '') create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '')
..add(const FourSceneInitial()) ..add(const FourSceneInitial())
..add(FourSceneInitialInfo()), ..add(const FourSceneInitialInfo())
..add(const FourSceneSwitchInitial()),
child: BlocBuilder<FourSceneBloc, FourSceneState>( child: BlocBuilder<FourSceneBloc, FourSceneState>(
builder: (context, state) { builder: (context, state) {
final sensor = BlocProvider.of<FourSceneBloc>(context); final _bloc = BlocProvider.of<FourSceneBloc>(context);
FourSceneModel model = FourSceneModel( FourSceneModelState model = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', scene_3: '',
@@ -54,9 +55,9 @@ class FourSceneScreen extends StatelessWidget {
scene_id_group_id: '', scene_id_group_id: '',
switch_backlight: ''); switch_backlight: '');
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.sosSensor; model = state.device;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.sensor; model = state.device;
} }
return state is FourSceneLoadingState return state is FourSceneLoadingState
? const Center( ? const Center(
@@ -67,7 +68,7 @@ class FourSceneScreen extends StatelessWidget {
) )
: RefreshIndicator( : RefreshIndicator(
onRefresh: () async { onRefresh: () async {
sensor.add(const FourSceneInitial()); _bloc.add(const FourSceneInitial());
}, },
child: ListView( child: ListView(
children: [ children: [
@@ -76,29 +77,45 @@ class FourSceneScreen extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
FourSwitchsCard( FourSwitchsCard(
switch1Down: sensor.switchStatus == true title1: _bloc.fourScene.isNotEmpty
? Assets.switchOn ? _bloc.fourScene[0].switchName
: Assets.switchOff, : 'title1',
switch1Up: sensor.switchStatus == true title2: _bloc.fourScene.length > 1
? Assets.switchOn ? _bloc.fourScene[1].switchName
: Assets.switchOff, : 'title2',
switch2Down: sensor.switchStatus == true title3: _bloc.fourScene.length > 2
? Assets.switchOn ? _bloc.fourScene[2].switchName
: Assets.switchOff, : 'title3',
switch2Up: sensor.switchStatus == true title4: _bloc.fourScene.length > 3
? Assets.switchOn ? _bloc.fourScene[3].switchName
: Assets.switchOff, : 'title4',
switch1:
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn
: Assets.switchOff,
switch2:
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn
: Assets.switchOff,
switch3:
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn
: Assets.switchOff,
switch4:
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn
: Assets.switchOff,
onSwitch1UpTap: () { onSwitch1UpTap: () {
debugPrint("Switch 1 Up tapped"); debugPrint("Switch 1 Up tapped");
}, },
onSwitch1DownTap: () {
debugPrint("Switch 1 Down tapped");
},
onSwitch2UpTap: () { onSwitch2UpTap: () {
debugPrint("Switch 2 Up tapped"); debugPrint("Switch 2 Up tapped");
}, },
onSwitch2DownTap: () { onSwitch3DownTap: () {
debugPrint("Switch 2 Down tapped"); debugPrint("onSwitch3DownTap");
},
onSwitch4DownTap: () {
debugPrint("onSwitch4DownTap");
}, },
), ),
Flexible( Flexible(
@@ -107,7 +124,7 @@ class FourSceneScreen extends StatelessWidget {
Expanded( Expanded(
child: DefaultContainer( child: DefaultContainer(
onTap: () { onTap: () {
sensor.add(ChangeSwitchStatusEvent()); _bloc.add(ChangeSwitchStatusEvent());
}, },
child: Column( child: Column(
crossAxisAlignment: crossAxisAlignment:
@@ -29,7 +29,7 @@ class FourSceneCreateGroup extends StatelessWidget {
child: BlocBuilder<FourSceneBloc, FourSceneState>( child: BlocBuilder<FourSceneBloc, FourSceneState>(
builder: (context, state) { builder: (context, state) {
final sensor = BlocProvider.of<FourSceneBloc>(context); final sensor = BlocProvider.of<FourSceneBloc>(context);
FourSceneModel model = FourSceneModel( FourSceneModelState model = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', scene_3: '',
@@ -37,9 +37,9 @@ class FourSceneCreateGroup extends StatelessWidget {
scene_id_group_id: '', scene_id_group_id: '',
switch_backlight: ''); switch_backlight: '');
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.sosSensor; model = state.device;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.sensor; model = state.device;
} }
return state is LoadingNewSate return state is LoadingNewSate
? const Center( ? const Center(
@@ -29,7 +29,7 @@ class FourSceneInfoPage extends StatelessWidget {
child: BlocBuilder<FourSceneBloc, FourSceneState>( child: BlocBuilder<FourSceneBloc, FourSceneState>(
builder: (context, state) { builder: (context, state) {
final _bloc = BlocProvider.of<FourSceneBloc>(context); final _bloc = BlocProvider.of<FourSceneBloc>(context);
FourSceneModel model = FourSceneModel( FourSceneModelState model = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', scene_3: '',
@@ -37,9 +37,9 @@ class FourSceneInfoPage extends StatelessWidget {
scene_id_group_id: '', scene_id_group_id: '',
switch_backlight: ''); switch_backlight: '');
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.sosSensor; model = state.device;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.sensor; model = state.device;
} }
return state is FourSceneLoadingState return state is FourSceneLoadingState
? const Center( ? const Center(
@@ -33,11 +33,11 @@ class FourSceneProfilePage extends StatelessWidget {
child: BlocProvider( child: BlocProvider(
create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '') create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '')
..add(const FourSceneInitial()) ..add(const FourSceneInitial())
..add(FourSceneInitialInfo()), ..add(const FourSceneInitialInfo()),
child: BlocBuilder<FourSceneBloc, FourSceneState>( child: BlocBuilder<FourSceneBloc, FourSceneState>(
builder: (context, state) { builder: (context, state) {
final _bloc = BlocProvider.of<FourSceneBloc>(context); final _bloc = BlocProvider.of<FourSceneBloc>(context);
FourSceneModel model = FourSceneModel( FourSceneModelState model = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', scene_3: '',
@@ -45,9 +45,9 @@ class FourSceneProfilePage extends StatelessWidget {
scene_id_group_id: '', scene_id_group_id: '',
switch_backlight: ''); switch_backlight: '');
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.sosSensor; model = state.device;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.sensor; model = state.device;
} }
return state is FourSceneLoadingState return state is FourSceneLoadingState
? const Center( ? const Center(
@@ -39,7 +39,7 @@ class FourSceneSettings extends StatelessWidget {
child: BlocBuilder<FourSceneBloc, FourSceneState>( child: BlocBuilder<FourSceneBloc, FourSceneState>(
builder: (context, state) { builder: (context, state) {
final _bloc = BlocProvider.of<FourSceneBloc>(context); final _bloc = BlocProvider.of<FourSceneBloc>(context);
FourSceneModel model = FourSceneModel( FourSceneModelState model = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', scene_3: '',
@@ -47,9 +47,9 @@ class FourSceneSettings extends StatelessWidget {
scene_id_group_id: '', scene_id_group_id: '',
switch_backlight: ''); switch_backlight: '');
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.sosSensor; model = state.device;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.sensor; model = state.device;
} }
return state is FourSceneLoadingState return state is FourSceneLoadingState
? const Center( ? const Center(
@@ -34,7 +34,7 @@ class LocationFourScenePage extends StatelessWidget {
child: BlocBuilder<FourSceneBloc, FourSceneState>( child: BlocBuilder<FourSceneBloc, FourSceneState>(
builder: (context, state) { builder: (context, state) {
final _bloc = BlocProvider.of<FourSceneBloc>(context); final _bloc = BlocProvider.of<FourSceneBloc>(context);
FourSceneModel model = FourSceneModel( FourSceneModelState model = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', scene_3: '',
@@ -29,7 +29,7 @@ class QuestionPageFourScene extends StatelessWidget {
child: BlocBuilder<FourSceneBloc, FourSceneState>( child: BlocBuilder<FourSceneBloc, FourSceneState>(
builder: (context, state) { builder: (context, state) {
final sensor = BlocProvider.of<FourSceneBloc>(context); final sensor = BlocProvider.of<FourSceneBloc>(context);
FourSceneModel model = FourSceneModel( FourSceneModelState model = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', scene_3: '',
@@ -37,9 +37,9 @@ class QuestionPageFourScene extends StatelessWidget {
scene_id_group_id: '', scene_id_group_id: '',
switch_backlight: ''); switch_backlight: '');
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.sosSensor; model = state.device;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.sensor; model = state.device;
} }
return state is FourSceneLoadingState return state is FourSceneLoadingState
? const Center( ? const Center(
@@ -25,7 +25,7 @@ class ShareFourScenePage extends StatelessWidget {
child: BlocBuilder<FourSceneBloc, FourSceneState>( child: BlocBuilder<FourSceneBloc, FourSceneState>(
builder: (context, state) { builder: (context, state) {
final sensor = BlocProvider.of<FourSceneBloc>(context); final sensor = BlocProvider.of<FourSceneBloc>(context);
FourSceneModel model = FourSceneModel( FourSceneModelState model = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', scene_3: '',
@@ -33,9 +33,9 @@ class ShareFourScenePage extends StatelessWidget {
scene_id_group_id: '', scene_id_group_id: '',
switch_backlight: ''); switch_backlight: '');
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.sosSensor; model = state.device;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.sensor; model = state.device;
} }
return state is LoadingNewSate return state is LoadingNewSate
? const Center( ? const Center(
@@ -68,6 +68,7 @@ class _FourSelectSwitchDialogState extends State<FourSelectSwitchDialog> {
}, },
onSwitch2DownTap: () { onSwitch2DownTap: () {
setState(() => selectedSwitchIndex = -2); setState(() => selectedSwitchIndex = -2);
}, },
), ),
@@ -3,25 +3,35 @@ import 'package:flutter_svg/svg.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class FourSwitchsCard extends StatelessWidget { class FourSwitchsCard extends StatelessWidget {
final String switch1Up; final String switch1;
final String switch1Down; final String title1;
final String switch2Up; final String switch3;
final String switch2Down; final String title3;
final String switch2;
final String title2;
final String switch4;
final String title4;
final VoidCallback onSwitch1UpTap; final VoidCallback onSwitch1UpTap;
final VoidCallback onSwitch1DownTap; final VoidCallback onSwitch4DownTap;
final VoidCallback onSwitch2UpTap; final VoidCallback onSwitch2UpTap;
final VoidCallback onSwitch2DownTap; final VoidCallback onSwitch3DownTap;
FourSwitchsCard({ FourSwitchsCard({
required this.switch1Down, required this.title1,
required this.switch1Up, required this.title2,
required this.switch2Down, required this.title3,
required this.switch2Up, required this.title4,
required this.switch3,
required this.switch1,
required this.switch4,
required this.switch2,
required this.onSwitch1UpTap, required this.onSwitch1UpTap,
required this.onSwitch1DownTap, required this.onSwitch3DownTap,
required this.onSwitch2UpTap, required this.onSwitch2UpTap,
required this.onSwitch2DownTap, required this.onSwitch4DownTap,
}); });
@override @override
@@ -73,9 +83,21 @@ class FourSwitchsCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [ children: [
_buildSwitchColumn(switch1Up, switch1Down, onSwitch1UpTap, onSwitch1DownTap), _buildSwitchColumn(
switchUp: switch1,
switchDown: switch3,
onUpTap: onSwitch1UpTap,
onDownTap: onSwitch3DownTap,
titleDown: title3,
titleUp: title1),
_buildDivider(), _buildDivider(),
_buildSwitchColumn(switch2Up, switch2Down, onSwitch2UpTap, onSwitch2DownTap), _buildSwitchColumn(
titleDown: title4,
titleUp: title2,
switchUp: switch2,
switchDown: switch4,
onUpTap: onSwitch2UpTap,
onDownTap: onSwitch4DownTap),
], ],
), ),
), ),
@@ -88,33 +110,45 @@ class FourSwitchsCard extends StatelessWidget {
); );
} }
Widget _buildSwitchColumn( Widget _buildSwitchColumn({
String switchUp, String switchUp = '',
String switchDown, String switchDown = '',
VoidCallback onUpTap, String titleUp = '',
VoidCallback onDownTap, String titleDown = '',
) { VoidCallback? onUpTap,
VoidCallback? onDownTap,
}) {
return Expanded( return Expanded(
child: Padding( child: Padding(
padding: const EdgeInsets.only(top: 30, bottom: 30), padding: const EdgeInsets.only(top: 30, bottom: 30),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
InkWell( Column(
onTap: onUpTap, children: [
child: Container( InkWell(
height: 20, onTap: onUpTap,
width: 20, child: Container(
child: SvgPicture.asset(switchUp), height: 20,
), width: 20,
child: SvgPicture.asset(switchUp),
),
),
Text(titleUp)
],
), ),
InkWell( Column(
onTap: onDownTap, children: [
child: Container( InkWell(
height: 20, onTap: onDownTap,
width: 20, child: Container(
child: SvgPicture.asset(switchDown), height: 20,
), width: 20,
child: SvgPicture.asset(switchDown),
),
),
Text(titleDown)
],
), ),
], ],
), ),
@@ -213,4 +213,5 @@ abstract class ApiEndpoints {
'/device/report-logs/{deviceUuid}?code={code}&startTime={startTime}&endTime={endTime}'; '/device/report-logs/{deviceUuid}?code={code}&startTime={startTime}&endTime={endTime}';
static const String controlBatch = '/device/control/batch'; static const String controlBatch = '/device/control/batch';
static const String statusBatch = '/device/status/batch'; static const String statusBatch = '/device/status/batch';
static const String getFourScene = '/device/four-scene/{deviceUuid}';
} }
+10 -1
View File
@@ -138,12 +138,21 @@ class DevicesAPI {
return response; 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 { static Future getDeviceInfo(String deviceId) async {
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId), path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) { expectedResponseModel: (json) {
print('object-=-=-$json');
return json; return json;
}); });
return response; return response;