mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-03-10 20:31:44 +00:00
code changes
This commit is contained in:
@ -62,6 +62,12 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
bool waterAlarm = false;
|
||||
static String deviceName = '';
|
||||
static String selectedRoomId = '';
|
||||
bool selecedScene = false;
|
||||
bool enableAlarm = false;
|
||||
List<FourSceneSwitchModel> fourScene = [];
|
||||
|
||||
String _selectedOption = '';
|
||||
bool _hasSelectionChanged = false;
|
||||
|
||||
FourSceneModelState deviceStatus = FourSceneModelState(
|
||||
scene_1: '',
|
||||
@ -103,36 +109,17 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
subspaceName: "",
|
||||
),
|
||||
);
|
||||
String selectedFormApiSceneId = '';
|
||||
|
||||
//============================ get Scene and assign scene =====================
|
||||
String selectedFormApiSceneId = '';
|
||||
String selectedSceneId = '';
|
||||
|
||||
_selectScene(SelectSceneEvent event, Emitter<FourSceneState> emit) {
|
||||
emit(FourSceneLoadingState());
|
||||
|
||||
selectedSceneId = event.selectedSceneId;
|
||||
emit(SceneSelectionUpdatedState(selectedSceneId: selectedSceneId));
|
||||
}
|
||||
|
||||
Future<void> saveName(
|
||||
SaveNameEvent event, Emitter<FourSceneState> emit) async {
|
||||
if (_validateInputs()) return;
|
||||
try {
|
||||
add(const ChangeNameEvent(value: false));
|
||||
isSaving = true;
|
||||
emit(FourSceneLoadingState());
|
||||
var response = await DevicesAPI.putDeviceName(
|
||||
deviceId: fourSceneId, deviceName: nameController.text);
|
||||
add(const FourSceneInitialInfo());
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(SaveState());
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
} finally {
|
||||
isSaving = false;
|
||||
}
|
||||
}
|
||||
|
||||
void getSceneByName(
|
||||
GetSceneBySwitchName event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
@ -146,12 +133,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
bool selecedScene = false;
|
||||
bool enableAlarm = false;
|
||||
|
||||
String _selectedOption = '';
|
||||
bool _hasSelectionChanged = false;
|
||||
|
||||
void _onOptionSelected(
|
||||
SelectOptionEvent event, Emitter<FourSceneState> emit) {
|
||||
emit(FourSceneLoadingState());
|
||||
@ -162,8 +143,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
hasSelectionChanged: _hasSelectionChanged));
|
||||
}
|
||||
|
||||
List<FourSceneSwitchModel> fourScene = [];
|
||||
|
||||
void _fetchFourSceneSwitches(
|
||||
FourSceneSwitchInitial event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
@ -195,37 +174,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
deleteDevice(DeleteDeviceEvent event, Emitter<FourSceneState> emit) async {
|
||||
try {
|
||||
emit(FourSceneLoadingState());
|
||||
var response = await DevicesAPI.resetDevise(devicesUuid: fourSceneId);
|
||||
CustomSnackBar.displaySnackBar('Reset Successfully');
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _fetchDeviceStatus(
|
||||
FourSceneInitial event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(fourSceneId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus = FourSceneModelState.fromJson(
|
||||
statusModelList,
|
||||
);
|
||||
add(const FourSceneSwitchInitial());
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void assignScene(
|
||||
AssignDeviceScene event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
@ -263,6 +211,8 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
//===================== fetch Device Status and info =======================
|
||||
|
||||
void _toggleLowBattery(
|
||||
ToggleEnableAlarmEvent event, Emitter<FourSceneState> emit) async {
|
||||
emit(LoadingNewSate(device: deviceStatus));
|
||||
@ -274,26 +224,24 @@ 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));
|
||||
// }
|
||||
// }
|
||||
void _fetchDeviceStatus(
|
||||
FourSceneInitial event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(fourSceneId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus = FourSceneModelState.fromJson(
|
||||
statusModelList,
|
||||
);
|
||||
add(const FourSceneSwitchInitial());
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future fetchDeviceInfo(
|
||||
FourSceneInitialInfo event, Emitter<FourSceneState> emit) async {
|
||||
@ -318,18 +266,8 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
emit(FaqSearchState(filteredFaqQuestions: _faqQuestions));
|
||||
}
|
||||
|
||||
void _changeName(ChangeNameEvent event, Emitter<FourSceneState> emit) {
|
||||
emit(FourSceneLoadingState());
|
||||
editName = event.value!;
|
||||
if (editName) {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
focusNode.requestFocus();
|
||||
});
|
||||
} else {
|
||||
focusNode.unfocus();
|
||||
}
|
||||
emit(NameEditingState(editName: editName));
|
||||
}
|
||||
//============================ assign Device ==================================
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void _toggleNotification(
|
||||
ToggleNotificationEvent event, Emitter<FourSceneState> emit) async {
|
||||
@ -337,15 +275,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
try {
|
||||
enableAlarm = event.isClosingEnabled;
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
// API call to update the state, if necessary
|
||||
// await DevicesAPI.controlDevice(
|
||||
// DeviceControlModel(
|
||||
// deviceId: sosId,
|
||||
// code: 'closing_reminder',
|
||||
// value: closingReminder,
|
||||
// ),
|
||||
// sosId,
|
||||
// );
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
@ -354,38 +283,50 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
DeviceReport recordGroups =
|
||||
DeviceReport(startTime: '0', endTime: '0', data: []);
|
||||
|
||||
//========================= Question and faq ================================
|
||||
|
||||
final List<QuestionModel> faqQuestions = [
|
||||
QuestionModel(
|
||||
id: 1,
|
||||
question: 'How does an SOS emergency button work?',
|
||||
question:
|
||||
'How does an 4 Scene Switch work? How long will an 4 Scene Switch persist?',
|
||||
answer:
|
||||
'The SOS emergency button sends an alert to your contacts when pressed.',
|
||||
'Yes. In scenes with high detection requirements, we recommend that you choose phone or message notification in Automation.',
|
||||
),
|
||||
QuestionModel(
|
||||
id: 2,
|
||||
question: 'How long will an SOS alarm persist?',
|
||||
question: 'Does the 4 Scene Switch support sending notifications?',
|
||||
answer:
|
||||
'The SOS alarm will persist until it is manually turned off or after a set time.',
|
||||
),
|
||||
QuestionModel(
|
||||
id: 3,
|
||||
question: 'What should I do if the SOS button is unresponsive?',
|
||||
question:
|
||||
'Why does the data statistics in the device panel not show the correct data?',
|
||||
answer: 'Try restarting the device. If it persists, contact support.',
|
||||
),
|
||||
QuestionModel(
|
||||
id: 4,
|
||||
question: 'Can I use the SOS feature without a network connection?',
|
||||
question:
|
||||
'How long will the App show offline after a device (low-power devices and normal devices) is powered...',
|
||||
answer:
|
||||
'No, a network connection is required to send the alert to your contacts.',
|
||||
),
|
||||
QuestionModel(
|
||||
id: 5,
|
||||
question: 'How often should I check the SOS battery?',
|
||||
answer:
|
||||
'Check the SOS battery at least once a month to ensure it is operational.',
|
||||
),
|
||||
];
|
||||
|
||||
bool isHelpful = false;
|
||||
|
||||
void _toggleHelpful(
|
||||
ToggleHelpfulEvent event, Emitter<FourSceneState> emit) async {
|
||||
try {
|
||||
emit(FourSceneLoadingState());
|
||||
isHelpful = event.isHelpful!;
|
||||
emit(SaveState());
|
||||
} catch (e) {
|
||||
emit(const FourSceneFailedState(errorMessage: 'Something went wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onFourSceneInitial(
|
||||
FourSceneInitialQuestion event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
@ -394,20 +335,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
|
||||
List<DeviceModel> allDevices = [];
|
||||
List<SubSpaceModel> roomsList = [];
|
||||
|
||||
void _fetchRoomsAndDevices(
|
||||
FetchRoomsEvent event, Emitter<FourSceneState> emit) async {
|
||||
try {
|
||||
emit(FourSceneLoadingState());
|
||||
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||
event.unit.community.uuid, event.unit.id);
|
||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||
} catch (e) {
|
||||
emit(const FourSceneFailedState(errorMessage: 'Something went wrong'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool switchStatus = true;
|
||||
Future<void> changeSwitchStatus(
|
||||
ChangeSwitchStatusEvent event, Emitter<FourSceneState> emit) async {
|
||||
@ -499,6 +426,8 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
emit(UpdateStateList(groupDevices: groupDevices, devices: devices));
|
||||
}
|
||||
|
||||
//=========================== assign device to room ==========================
|
||||
|
||||
void _assignDevice(
|
||||
AssignRoomEvent event, Emitter<FourSceneState> emit) async {
|
||||
try {
|
||||
@ -525,6 +454,35 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _fetchRoomsAndDevices(
|
||||
FetchRoomsEvent event, Emitter<FourSceneState> emit) async {
|
||||
try {
|
||||
emit(FourSceneLoadingState());
|
||||
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||
event.unit.community.uuid, event.unit.id);
|
||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||
} catch (e) {
|
||||
emit(const FourSceneFailedState(errorMessage: 'Something went wrong'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//============================ setting name ==================================
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void _changeName(ChangeNameEvent event, Emitter<FourSceneState> emit) {
|
||||
emit(FourSceneLoadingState());
|
||||
editName = event.value!;
|
||||
if (editName) {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
focusNode.requestFocus();
|
||||
});
|
||||
} else {
|
||||
focusNode.unfocus();
|
||||
}
|
||||
emit(NameEditingState(editName: editName));
|
||||
}
|
||||
|
||||
bool _validateInputs() {
|
||||
final nameError = fullNameValidator(nameController.text);
|
||||
if (nameError != null) {
|
||||
@ -546,6 +504,27 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> saveName(
|
||||
SaveNameEvent event, Emitter<FourSceneState> emit) async {
|
||||
if (_validateInputs()) return;
|
||||
try {
|
||||
add(const ChangeNameEvent(value: false));
|
||||
isSaving = true;
|
||||
emit(FourSceneLoadingState());
|
||||
var response = await DevicesAPI.putDeviceName(
|
||||
deviceId: fourSceneId, deviceName: nameController.text);
|
||||
add(const FourSceneInitialInfo());
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(SaveState());
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
} finally {
|
||||
isSaving = false;
|
||||
}
|
||||
}
|
||||
|
||||
//====================== update device ==============================
|
||||
|
||||
bool enableUpdate = false;
|
||||
|
||||
void _toggleUpdate(
|
||||
@ -559,16 +538,15 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
bool isHelpful = false;
|
||||
|
||||
void _toggleHelpful(
|
||||
ToggleHelpfulEvent event, Emitter<FourSceneState> emit) async {
|
||||
deleteDevice(DeleteDeviceEvent event, Emitter<FourSceneState> emit) async {
|
||||
try {
|
||||
emit(FourSceneLoadingState());
|
||||
isHelpful = event.isHelpful!;
|
||||
emit(SaveState());
|
||||
var response = await DevicesAPI.resetDevise(devicesUuid: fourSceneId);
|
||||
CustomSnackBar.displaySnackBar('Reset Successfully');
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(const FourSceneFailedState(errorMessage: 'Something went wrong'));
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,21 +10,6 @@ abstract class FourSceneEvent extends Equatable {
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class FourSceneLoading extends FourSceneEvent {}
|
||||
|
||||
class FourSceneSwitch extends FourSceneEvent {
|
||||
final String switchD;
|
||||
final String deviceId;
|
||||
final String productId;
|
||||
const FourSceneSwitch(
|
||||
{required this.switchD, this.deviceId = '', this.productId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [switchD, deviceId, productId];
|
||||
}
|
||||
|
||||
class FourSceneUpdated extends FourSceneEvent {}
|
||||
|
||||
class FourSceneInitialInfo extends FourSceneEvent {
|
||||
const FourSceneInitialInfo();
|
||||
}
|
||||
@ -39,19 +24,6 @@ class SaveNameEvent extends FourSceneEvent {
|
||||
const SaveNameEvent({this.deviceName});
|
||||
}
|
||||
|
||||
class ReportLogsInitial extends FourSceneEvent {
|
||||
const ReportLogsInitial();
|
||||
}
|
||||
|
||||
class FourSceneChangeStatus extends FourSceneEvent {}
|
||||
|
||||
class GetCounterEvent extends FourSceneEvent {
|
||||
final String deviceCode;
|
||||
const GetCounterEvent({required this.deviceCode});
|
||||
@override
|
||||
List<Object> get props => [deviceCode];
|
||||
}
|
||||
|
||||
class ToggleEnableAlarmEvent extends FourSceneEvent {
|
||||
final bool isLowBatteryEnabled;
|
||||
|
||||
@ -70,44 +42,6 @@ class ToggleNotificationEvent extends FourSceneEvent {
|
||||
List<Object> get props => [isClosingEnabled];
|
||||
}
|
||||
|
||||
class ToggleFourSceneAlarmEvent extends FourSceneEvent {
|
||||
final bool isFourSceneAlarmEnabled;
|
||||
|
||||
const ToggleFourSceneAlarmEvent(this.isFourSceneAlarmEnabled);
|
||||
|
||||
@override
|
||||
List<Object> get props => [isFourSceneAlarmEnabled];
|
||||
}
|
||||
|
||||
class SetCounterValue extends FourSceneEvent {
|
||||
final Duration duration;
|
||||
final String deviceCode;
|
||||
const SetCounterValue({required this.duration, required this.deviceCode});
|
||||
@override
|
||||
List<Object> get props => [duration, deviceCode];
|
||||
}
|
||||
|
||||
class StartTimer extends FourSceneEvent {
|
||||
final int duration;
|
||||
|
||||
const StartTimer(this.duration);
|
||||
|
||||
@override
|
||||
List<Object> get props => [duration];
|
||||
}
|
||||
|
||||
class TickTimer extends FourSceneEvent {
|
||||
final int remainingTime;
|
||||
|
||||
const TickTimer(this.remainingTime);
|
||||
|
||||
@override
|
||||
List<Object> get props => [remainingTime];
|
||||
}
|
||||
|
||||
class StopTimer extends FourSceneEvent {}
|
||||
|
||||
class OnClose extends FourSceneEvent {}
|
||||
class DeleteDeviceEvent extends FourSceneEvent {}
|
||||
|
||||
class ChangeNameEvent extends FourSceneEvent {
|
||||
@ -164,11 +98,9 @@ class SearchScenesEvent extends FourSceneEvent {
|
||||
});
|
||||
}
|
||||
|
||||
class SaveLocationSelectionEvent extends FourSceneEvent {}
|
||||
|
||||
class SelectOptionEvent extends FourSceneEvent {
|
||||
final dynamic selectedOption;
|
||||
const SelectOptionEvent({
|
||||
final dynamic selectedOption;
|
||||
const SelectOptionEvent({
|
||||
this.selectedOption,
|
||||
});
|
||||
}
|
||||
@ -176,14 +108,14 @@ class SelectOptionEvent extends FourSceneEvent {
|
||||
class AddDeviceToGroup extends FourSceneEvent {
|
||||
final GroupDevicesModel device;
|
||||
final String icon;
|
||||
AddDeviceToGroup(this.device, this.icon);
|
||||
const AddDeviceToGroup(this.device, this.icon);
|
||||
}
|
||||
|
||||
class RemoveDeviceFromGroup extends FourSceneEvent {
|
||||
final GroupDevicesModel device;
|
||||
final String icon;
|
||||
|
||||
RemoveDeviceFromGroup(this.device, this.icon);
|
||||
const RemoveDeviceFromGroup(this.device, this.icon);
|
||||
}
|
||||
|
||||
class AssignRoomEvent extends FourSceneEvent {
|
||||
@ -207,15 +139,10 @@ class AssignRoomEvent extends FourSceneEvent {
|
||||
|
||||
class FetchDeviceScene extends FourSceneEvent {}
|
||||
|
||||
|
||||
class FourSceneSwitchInitial extends FourSceneEvent {
|
||||
const FourSceneSwitchInitial();
|
||||
}
|
||||
|
||||
class SaveSelectionSceneEvent extends FourSceneEvent {
|
||||
const SaveSelectionSceneEvent();
|
||||
}
|
||||
|
||||
class AssignDeviceScene extends FourSceneEvent {
|
||||
final String? sceneUuid;
|
||||
final String? switchName;
|
||||
@ -232,13 +159,13 @@ class GetSceneBySwitchName extends FourSceneEvent {
|
||||
|
||||
const GetSceneBySwitchName({this.switchName});
|
||||
}
|
||||
|
||||
class ToggleUpdateEvent extends FourSceneEvent {
|
||||
final bool? isUpdateEnabled;
|
||||
const ToggleUpdateEvent({this.isUpdateEnabled});
|
||||
}
|
||||
|
||||
|
||||
class ToggleHelpfulEvent extends FourSceneEvent {
|
||||
final bool? isHelpful;
|
||||
const ToggleHelpfulEvent({this.isHelpful});
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,12 +14,8 @@ class FourSceneState extends Equatable {
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class FourSceneInitialState extends FourSceneState {}
|
||||
|
||||
class FourSceneLoadingState extends FourSceneState {}
|
||||
|
||||
class FourSceState extends FourSceneState {}
|
||||
|
||||
class UpdateStateList extends FourSceneState {
|
||||
final List<GroupDevicesModel> groupDevices;
|
||||
final List<GroupDevicesModel> devices;
|
||||
@ -60,7 +56,7 @@ class NameEditingState extends FourSceneState {
|
||||
class FaqLoadedState extends FourSceneState {
|
||||
final List<QuestionModel> filteredFaqQuestions;
|
||||
|
||||
FaqLoadedState({this.filteredFaqQuestions = const []});
|
||||
const FaqLoadedState({this.filteredFaqQuestions = const []});
|
||||
}
|
||||
|
||||
class FaqSearchState extends FourSceneState {
|
||||
@ -94,8 +90,6 @@ class SceneLoaded extends FourSceneState {
|
||||
{this.loadingSceneId, this.loadingStates = const {}});
|
||||
}
|
||||
|
||||
class SelectedSceneState extends FourSceneState {}
|
||||
|
||||
class SearchResultsState extends FourSceneState {}
|
||||
|
||||
class SaveState extends FourSceneState {}
|
||||
@ -106,7 +100,7 @@ class OptionSelectedState extends FourSceneState {
|
||||
final String selectedOption;
|
||||
final bool hasSelectionChanged;
|
||||
|
||||
OptionSelectedState({
|
||||
const OptionSelectedState({
|
||||
required this.selectedOption,
|
||||
required this.hasSelectionChanged,
|
||||
});
|
||||
@ -126,5 +120,5 @@ class LoadingDeviceInfo extends FourSceneState {
|
||||
class SceneSelectionUpdatedState extends FourSceneState {
|
||||
final String selectedSceneId;
|
||||
|
||||
SceneSelectionUpdatedState({required this.selectedSceneId});
|
||||
const SceneSelectionUpdatedState({required this.selectedSceneId});
|
||||
}
|
||||
|
||||
@ -11,7 +11,8 @@ import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dar
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class AlarmManagementPage extends StatelessWidget {
|
||||
const AlarmManagementPage({super.key});
|
||||
final String sosId;
|
||||
const AlarmManagementPage({super.key, required this.sosId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@ -29,18 +29,15 @@ class SosScreen extends StatelessWidget {
|
||||
child: BlocBuilder<SosBloc, SosState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<SosBloc>(context);
|
||||
// Default SOS model in case no state is loaded
|
||||
SosModel model = SosModel(
|
||||
batteryPercentage: 0,
|
||||
sosContactState: '',
|
||||
);
|
||||
// Update the model based on the state
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
}
|
||||
|
||||
return DefaultScaffold(
|
||||
title: sensor.deviceInfo.name,
|
||||
actions: [
|
||||
@ -183,7 +180,9 @@ class SosScreen extends StatelessWidget {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const AlarmManagementPage(),
|
||||
AlarmManagementPage(
|
||||
sosId: device!.uuid!,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||
@ -6,11 +5,9 @@ import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/sos_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class LocationSosPage extends StatelessWidget {
|
||||
@ -39,8 +36,8 @@ class LocationSosPage extends StatelessWidget {
|
||||
SosModel model =
|
||||
SosModel(batteryPercentage: 0, sosContactState: '');
|
||||
if (state is SaveSelectionSuccessState) {
|
||||
new Future.delayed(const Duration(microseconds: 500), () {
|
||||
_bloc.add(SosInitial());
|
||||
Future.delayed(const Duration(microseconds: 500), () {
|
||||
_bloc.add(const SosInitial());
|
||||
Navigator.of(context).pop(true);
|
||||
});
|
||||
}
|
||||
@ -80,64 +77,59 @@ class LocationSosPage extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
],
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
// sensor.add(const SosInitial());
|
||||
},
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||
children: [
|
||||
const BodyMedium(
|
||||
text: 'Smart Device Location',
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 12,
|
||||
fontColor: ColorsManager.grayColor,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
DefaultContainer(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: ListView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: _bloc.roomsList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final fromRoom = _bloc.roomsList[index];
|
||||
final isSelected = (state
|
||||
is OptionSelectedState &&
|
||||
state.selectedOption == fromRoom.id) ||
|
||||
(state is! OptionSelectedState &&
|
||||
fromRoom.id ==
|
||||
_bloc.deviceInfo.subspace.uuid);
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||
children: [
|
||||
const BodyMedium(
|
||||
text: 'Smart Device Location',
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 12,
|
||||
fontColor: ColorsManager.grayColor,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
DefaultContainer(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: ListView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: _bloc.roomsList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final fromRoom = _bloc.roomsList[index];
|
||||
final isSelected = (state
|
||||
is OptionSelectedState &&
|
||||
state.selectedOption == fromRoom.id) ||
|
||||
(state is! OptionSelectedState &&
|
||||
fromRoom.id ==
|
||||
_bloc.deviceInfo.subspace.uuid);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_buildCheckboxOption(
|
||||
label: fromRoom.name!,
|
||||
isSelected: isSelected,
|
||||
onTap: (label) {
|
||||
context.read<SosBloc>().add(
|
||||
SelectOptionEvent(
|
||||
selectedOption: fromRoom.id!,
|
||||
),
|
||||
);
|
||||
roomIdSelected = fromRoom.id!;
|
||||
},
|
||||
return Column(
|
||||
children: [
|
||||
_buildCheckboxOption(
|
||||
label: fromRoom.name!,
|
||||
isSelected: isSelected,
|
||||
onTap: (label) {
|
||||
context.read<SosBloc>().add(
|
||||
SelectOptionEvent(
|
||||
selectedOption: fromRoom.id!,
|
||||
),
|
||||
);
|
||||
roomIdSelected = fromRoom.id!;
|
||||
},
|
||||
),
|
||||
if (index < _bloc.roomsList.length - 1) ...[
|
||||
const SizedBox(height: 10),
|
||||
const Divider(
|
||||
color: ColorsManager.dividerColor,
|
||||
),
|
||||
if (index < _bloc.roomsList.length - 1) ...[
|
||||
const SizedBox(height: 10),
|
||||
const Divider(
|
||||
color: ColorsManager.dividerColor,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@ -5,7 +5,6 @@ import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/question_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/sos_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_button.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
@ -28,13 +27,7 @@ class QuestionPage extends StatelessWidget {
|
||||
child: BlocBuilder<SosBloc, SosState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<SosBloc>(context);
|
||||
SosModel model =
|
||||
SosModel(batteryPercentage: 0, sosContactState: 'normal');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
}
|
||||
|
||||
return state is SosLoadingState
|
||||
? const Center(
|
||||
child: DefaultContainer(
|
||||
@ -42,109 +35,105 @@ class QuestionPage extends StatelessWidget {
|
||||
height: 50,
|
||||
child: CircularProgressIndicator()),
|
||||
)
|
||||
: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
sensor.add(const SosInitial());
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
DefaultContainer(
|
||||
padding: EdgeInsets.all(15),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BodyLarge(
|
||||
text: questionModel!.question,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontColor: ColorsManager.blackColor,
|
||||
),
|
||||
SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
BodyMedium(
|
||||
text: questionModel!.answer,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontColor: ColorsManager.secondaryTextColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
: Column(
|
||||
children: [
|
||||
DefaultContainer(
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BodyLarge(
|
||||
text: questionModel!.question,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontColor: ColorsManager.blackColor,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
BodyMedium(
|
||||
text: questionModel!.answer,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontColor: ColorsManager.secondaryTextColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.15,
|
||||
),
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.15,
|
||||
),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: 180,
|
||||
child: DefaultButton(
|
||||
backgroundColor: sensor.isHelpful == true
|
||||
? ColorsManager.grayColor
|
||||
: ColorsManager.grayButtonColors,
|
||||
borderRadius: 50,
|
||||
onPressed: () {
|
||||
sensor.add(
|
||||
const ToggleHelpfulEvent(isHelpful: true));
|
||||
},
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
Assets.thumbUp,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
const BodyMedium(
|
||||
text: 'Helpful',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontColor: ColorsManager.blackColor,
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: 180,
|
||||
child: DefaultButton(
|
||||
backgroundColor: sensor.isHelpful == true
|
||||
? ColorsManager.grayColor
|
||||
: ColorsManager.grayButtonColors,
|
||||
borderRadius: 50,
|
||||
onPressed: () {
|
||||
sensor
|
||||
.add(ToggleHelpfulEvent(isHelpful: true));
|
||||
},
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
Assets.thumbUp,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
const BodyMedium(
|
||||
text: 'Helpful',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontColor: ColorsManager.blackColor,
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: 180,
|
||||
child: DefaultButton(
|
||||
backgroundColor: sensor.isHelpful == false
|
||||
? ColorsManager.grayColor
|
||||
: ColorsManager.grayButtonColors,
|
||||
borderRadius: 50,
|
||||
onPressed: () {
|
||||
sensor.add(
|
||||
const ToggleHelpfulEvent(isHelpful: false));
|
||||
},
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
Assets.thumbDown,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
const BodyMedium(
|
||||
text: 'Not Helpful',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontColor: ColorsManager.blackColor,
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: 180,
|
||||
child: DefaultButton(
|
||||
backgroundColor: sensor.isHelpful == false
|
||||
? ColorsManager.grayColor
|
||||
: ColorsManager.grayButtonColors,
|
||||
borderRadius: 50,
|
||||
onPressed: () {
|
||||
sensor.add(
|
||||
ToggleHelpfulEvent(isHelpful: false));
|
||||
},
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
Assets.thumbDown,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
const BodyMedium(
|
||||
text: 'Not Helpful',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontColor: ColorsManager.blackColor,
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@ -5,7 +5,6 @@ import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/sos_model.dart';
|
||||
import 'package:syncrow_app/features/menu/view/widgets/manage_home/home_settings.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_button.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
@ -32,13 +31,6 @@ class ShareSosPage extends StatelessWidget {
|
||||
child: BlocBuilder<SosBloc, SosState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<SosBloc>(context);
|
||||
SosModel model =
|
||||
SosModel(batteryPercentage: 0, sosContactState: 'normal');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
}
|
||||
return state is SosLoadingState
|
||||
? const Center(
|
||||
child: DefaultContainer(
|
||||
@ -100,7 +92,7 @@ class ShareSosPage extends StatelessWidget {
|
||||
space: spaces!.first,
|
||||
)));
|
||||
},
|
||||
child: Text('Add Home Member')),
|
||||
child: const Text('Add Home Member')),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
||||
@ -5,7 +5,6 @@ import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/sos_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
@ -29,13 +28,6 @@ class SosInfoPage extends StatelessWidget {
|
||||
child: BlocBuilder<SosBloc, SosState>(
|
||||
builder: (context, state) {
|
||||
final _bloc = BlocProvider.of<SosBloc>(context);
|
||||
SosModel model =
|
||||
SosModel(batteryPercentage: 0, sosContactState: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
}
|
||||
return state is SosLoadingState
|
||||
? const Center(
|
||||
child: DefaultContainer(
|
||||
|
||||
Reference in New Issue
Block a user