mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 07:49:40 +00:00
sos
This commit is contained in:
@ -41,7 +41,6 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
on<SaveNameEvent>(saveName);
|
||||
on<ToggleUpdateEvent>(_toggleUpdate);
|
||||
on<ToggleHelpfulEvent>(_toggleHelpful);
|
||||
// on<ToggleWaterLeakAlarmEvent>(_toggleWaterLeakAlarm);
|
||||
}
|
||||
|
||||
final TextEditingController nameController =
|
||||
@ -49,34 +48,11 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
bool isSaving = false;
|
||||
bool editName = false;
|
||||
final FocusNode focusNode = FocusNode();
|
||||
Timer? _timer;
|
||||
bool enableAlarm = false;
|
||||
bool closingReminder = false;
|
||||
bool waterAlarm = false;
|
||||
SosModel deviceStatus =
|
||||
SosModel(sosContactState: 'sos', batteryPercentage: 0);
|
||||
|
||||
void _fetchStatus(SosInitial event, Emitter<SosState> emit) async {
|
||||
emit(SosLoadingState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(sosId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus = SosModel.fromJson(
|
||||
statusModelList,
|
||||
);
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
// _listenToChanges();
|
||||
} catch (e) {
|
||||
emit(SosFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DeviceInfoModel deviceInfo = DeviceInfoModel(
|
||||
activeTime: 0,
|
||||
category: "",
|
||||
@ -110,29 +86,6 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
),
|
||||
);
|
||||
|
||||
void _onSearchFaq(SearchFaqEvent event, Emitter<SosState> emit) {
|
||||
emit(SosLoadingState());
|
||||
List<QuestionModel> _faqQuestions = faqQuestions.where((question) {
|
||||
return question.question
|
||||
.toLowerCase()
|
||||
.contains(event.query.toLowerCase());
|
||||
}).toList();
|
||||
emit(FaqSearchState(filteredFaqQuestions: _faqQuestions));
|
||||
}
|
||||
|
||||
void _changeName(ChangeNameEvent event, Emitter<SosState> emit) {
|
||||
emit(SosLoadingState());
|
||||
editName = event.value!;
|
||||
if (editName) {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
focusNode.requestFocus();
|
||||
});
|
||||
} else {
|
||||
focusNode.unfocus();
|
||||
}
|
||||
emit(NameEditingState(editName: editName));
|
||||
}
|
||||
|
||||
void _toggleLowBattery(
|
||||
ToggleEnableAlarmEvent event, Emitter<SosState> emit) async {
|
||||
emit(LoadingNewSate(sosSensor: deviceStatus));
|
||||
@ -189,6 +142,8 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
}
|
||||
}
|
||||
|
||||
//========================= Device Info & Status =============================
|
||||
|
||||
static String deviceName = '';
|
||||
|
||||
fetchDeviceInfo(SosInitialDeviseInfo event, Emitter<SosState> emit) async {
|
||||
@ -203,48 +158,29 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
}
|
||||
}
|
||||
|
||||
// Demo list of FAQ questions using the QuestionModel class
|
||||
final List<QuestionModel> faqQuestions = [
|
||||
QuestionModel(
|
||||
id: 1,
|
||||
question: 'How does an SOS emergency button work?',
|
||||
answer:
|
||||
'The SOS emergency button sends an alert to your contacts when pressed.',
|
||||
),
|
||||
QuestionModel(
|
||||
id: 2,
|
||||
question: 'How long will an SOS alarm persist?',
|
||||
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?',
|
||||
answer: 'Try restarting the device. If it persists, contact support.',
|
||||
),
|
||||
QuestionModel(
|
||||
id: 4,
|
||||
question: 'Can I use the SOS feature without a network connection?',
|
||||
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.',
|
||||
),
|
||||
];
|
||||
Future<void> _onSosInitial(
|
||||
SosInitialQuestion event, Emitter<SosState> emit) async {
|
||||
void _fetchStatus(SosInitial event, Emitter<SosState> emit) async {
|
||||
emit(SosLoadingState());
|
||||
// SosModel sosModel = await fetchSosData(sosId); // Define this function as needed
|
||||
emit(FaqLoadedState(filteredFaqQuestions: faqQuestions));
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(sosId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus = SosModel.fromJson(
|
||||
statusModelList,
|
||||
);
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
} catch (e) {
|
||||
emit(SosFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//========================= assign & unassign devise to room =============================
|
||||
List<DeviceModel> allDevices = [];
|
||||
List<SubSpaceModel> roomsList = [];
|
||||
|
||||
void _fetchRoomsAndDevices(
|
||||
FetchRoomsEvent event, Emitter<SosState> emit) async {
|
||||
try {
|
||||
@ -279,9 +215,6 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
_hasSelectionChanged = false;
|
||||
add(AssignRoomEvent(roomId: roomId, unit: unit, context: event.context));
|
||||
emit(SaveSelectionSuccessState());
|
||||
|
||||
// Navigator.pushNamedAndRemoveUntil(
|
||||
// event.context, Routes.homeRoute, (route) => false);
|
||||
var cubit = HomeCubit.getInstance();
|
||||
cubit.updatePageIndex(1);
|
||||
Navigator.pushReplacementNamed(event.context, Routes.homeRoute);
|
||||
@ -290,7 +223,6 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
|
||||
void _assignDevice(AssignRoomEvent event, Emitter<SosState> emit) async {
|
||||
try {
|
||||
// Map<String, bool> roomDevicesId = {};
|
||||
emit(SosLoadingState());
|
||||
|
||||
await HomeManagementAPI.assignDeviceToRoom(
|
||||
@ -339,11 +271,6 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
roomDevicesId[e.uuid!] = false;
|
||||
}
|
||||
});
|
||||
// emit(FetchDeviceByRoomIdState(
|
||||
// roomDevices: devicesList,
|
||||
// allDevices: allDevices,
|
||||
// roomDevicesId: roomDevicesId,
|
||||
// roomId: event.roomId));
|
||||
} catch (e) {
|
||||
emit(const SosFailedState(errorMessage: 'Something went wrong'));
|
||||
return;
|
||||
@ -352,46 +279,7 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
|
||||
Map<String, List<DeviceModel>> devicesByRoom = {};
|
||||
|
||||
// Your existing function
|
||||
void _fetchDevicesByRoomId(
|
||||
FetchDevicesByRoomIdEvent event, Emitter<SosState> emit) async {
|
||||
try {
|
||||
Map<String, bool> roomDevicesId = {};
|
||||
emit(SosLoadingState());
|
||||
|
||||
// Fetch devices for the specified room
|
||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||
communityUuid: event.unit.community.uuid,
|
||||
spaceUuid: event.unit.id,
|
||||
roomId: event.roomId);
|
||||
|
||||
// Fetch all devices accessible by the user
|
||||
allDevices = await HomeManagementAPI.fetchDevicesByUserId();
|
||||
|
||||
// Map all accessible device IDs
|
||||
List<String> allDevicesIds = [];
|
||||
allDevices.forEach((element) {
|
||||
allDevicesIds.add(element.uuid!);
|
||||
});
|
||||
|
||||
// Mark devices as accessible/inaccessible for the room and add to devicesByRoom map
|
||||
devicesList.forEach((e) {
|
||||
roomDevicesId[e.uuid!] = allDevicesIds.contains(e.uuid!);
|
||||
});
|
||||
|
||||
// Update the devicesByRoom map with the devices in the current room
|
||||
devicesByRoom[event.roomId] = devicesList;
|
||||
|
||||
// emit(FetchDeviceByRoomIdState(
|
||||
// roomDevices: devicesList,
|
||||
// allDevices: allDevices,
|
||||
// roomDevicesId: roomDevicesId,
|
||||
// roomId: event.roomId));
|
||||
} catch (e) {
|
||||
emit(const SosFailedState(errorMessage: 'Something went wrong'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
//======================= setting name ======================================
|
||||
|
||||
Future<void> saveName(SaveNameEvent event, Emitter<SosState> emit) async {
|
||||
if (_validateInputs()) return;
|
||||
@ -432,6 +320,20 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
return null;
|
||||
}
|
||||
|
||||
void _changeName(ChangeNameEvent event, Emitter<SosState> emit) {
|
||||
emit(SosLoadingState());
|
||||
editName = event.value!;
|
||||
if (editName) {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
focusNode.requestFocus();
|
||||
});
|
||||
} else {
|
||||
focusNode.unfocus();
|
||||
}
|
||||
emit(NameEditingState(editName: editName));
|
||||
}
|
||||
|
||||
//============================== update setting ===============================
|
||||
bool enableUpdate = false;
|
||||
|
||||
void _toggleUpdate(ToggleUpdateEvent event, Emitter<SosState> emit) async {
|
||||
@ -444,8 +346,57 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
}
|
||||
}
|
||||
|
||||
bool isHelpful = false;
|
||||
//============================ Question and faq ============================
|
||||
|
||||
final List<QuestionModel> faqQuestions = [
|
||||
QuestionModel(
|
||||
id: 1,
|
||||
question: 'How does an SOS emergency button work?',
|
||||
answer:
|
||||
'The SOS emergency button sends an alert to your contacts when pressed.',
|
||||
),
|
||||
QuestionModel(
|
||||
id: 2,
|
||||
question: 'How long will an SOS alarm persist?',
|
||||
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?',
|
||||
answer: 'Try restarting the device. If it persists, contact support.',
|
||||
),
|
||||
QuestionModel(
|
||||
id: 4,
|
||||
question: 'Can I use the SOS feature without a network connection?',
|
||||
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.',
|
||||
),
|
||||
];
|
||||
|
||||
Future<void> _onSosInitial(
|
||||
SosInitialQuestion event, Emitter<SosState> emit) async {
|
||||
emit(SosLoadingState());
|
||||
emit(FaqLoadedState(filteredFaqQuestions: faqQuestions));
|
||||
}
|
||||
|
||||
void _onSearchFaq(SearchFaqEvent event, Emitter<SosState> emit) {
|
||||
emit(SosLoadingState());
|
||||
List<QuestionModel> _faqQuestions = faqQuestions.where((question) {
|
||||
return question.question
|
||||
.toLowerCase()
|
||||
.contains(event.query.toLowerCase());
|
||||
}).toList();
|
||||
emit(FaqSearchState(filteredFaqQuestions: _faqQuestions));
|
||||
}
|
||||
|
||||
bool isHelpful = false;
|
||||
void _toggleHelpful(ToggleHelpfulEvent event, Emitter<SosState> emit) async {
|
||||
try {
|
||||
emit(SosLoadingState());
|
||||
@ -456,6 +407,8 @@ class SosBloc extends Bloc<SosEvent, SosState> {
|
||||
}
|
||||
}
|
||||
|
||||
//===================== delete Device ===================================
|
||||
|
||||
deleteDevice(DeleteDeviceEvent event, Emitter<SosState> emit) async {
|
||||
try {
|
||||
emit(SosLoadingState());
|
||||
|
@ -11,21 +11,8 @@ abstract class SosEvent extends Equatable {
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SosLoading extends SosEvent {}
|
||||
class DeleteDeviceEvent extends SosLoading {}
|
||||
class DeleteDeviceEvent extends SosEvent {}
|
||||
|
||||
class SosSwitch extends SosEvent {
|
||||
final String switchD;
|
||||
final String deviceId;
|
||||
final String productId;
|
||||
const SosSwitch(
|
||||
{required this.switchD, this.deviceId = '', this.productId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [switchD, deviceId, productId];
|
||||
}
|
||||
|
||||
class SosUpdated extends SosEvent {}
|
||||
class SosInitialDeviseInfo extends SosEvent {}
|
||||
|
||||
class SosInitial extends SosEvent {
|
||||
@ -36,15 +23,6 @@ class ReportLogsInitial extends SosEvent {
|
||||
const ReportLogsInitial();
|
||||
}
|
||||
|
||||
class SosChangeStatus extends SosEvent {}
|
||||
|
||||
class GetCounterEvent extends SosEvent {
|
||||
final String deviceCode;
|
||||
const GetCounterEvent({required this.deviceCode});
|
||||
@override
|
||||
List<Object> get props => [deviceCode];
|
||||
}
|
||||
|
||||
class ToggleEnableAlarmEvent extends SosEvent {
|
||||
final bool isLowBatteryEnabled;
|
||||
|
||||
@ -63,44 +41,6 @@ class ToggleClosingReminderEvent extends SosEvent {
|
||||
List<Object> get props => [isClosingReminderEnabled];
|
||||
}
|
||||
|
||||
class ToggleSosAlarmEvent extends SosEvent {
|
||||
final bool isSosAlarmEnabled;
|
||||
|
||||
const ToggleSosAlarmEvent(this.isSosAlarmEnabled);
|
||||
|
||||
@override
|
||||
List<Object> get props => [isSosAlarmEnabled];
|
||||
}
|
||||
|
||||
class SetCounterValue extends SosEvent {
|
||||
final Duration duration;
|
||||
final String deviceCode;
|
||||
const SetCounterValue({required this.duration, required this.deviceCode});
|
||||
@override
|
||||
List<Object> get props => [duration, deviceCode];
|
||||
}
|
||||
|
||||
class StartTimer extends SosEvent {
|
||||
final int duration;
|
||||
|
||||
const StartTimer(this.duration);
|
||||
|
||||
@override
|
||||
List<Object> get props => [duration];
|
||||
}
|
||||
|
||||
class TickTimer extends SosEvent {
|
||||
final int remainingTime;
|
||||
|
||||
const TickTimer(this.remainingTime);
|
||||
|
||||
@override
|
||||
List<Object> get props => [remainingTime];
|
||||
}
|
||||
|
||||
class StopTimer extends SosEvent {}
|
||||
|
||||
class OnClose extends SosEvent {}
|
||||
class SaveNameEvent extends SosEvent {}
|
||||
|
||||
class ChangeNameEvent extends SosEvent {
|
||||
@ -127,7 +67,6 @@ class FetchRoomsEvent extends SosEvent {
|
||||
List<Object> get props => [unit];
|
||||
}
|
||||
|
||||
|
||||
class SelectOptionEvent extends SosEvent {
|
||||
dynamic selectedOption;
|
||||
SelectOptionEvent({
|
||||
@ -160,6 +99,7 @@ class AssignRoomEvent extends SosEvent {
|
||||
context,
|
||||
];
|
||||
}
|
||||
|
||||
class UnassignRoomEvent extends SosEvent {
|
||||
final String roomId;
|
||||
final String deviceId;
|
||||
@ -172,25 +112,9 @@ class UnassignRoomEvent extends SosEvent {
|
||||
List<Object> get props => [roomId, unit];
|
||||
}
|
||||
|
||||
class FetchDevicesByRoomIdEvent extends SosEvent {
|
||||
final SpaceModel unit; // Represents the unit (e.g., room or space) context
|
||||
final String roomId; // Unique identifier for the room
|
||||
|
||||
// Constructor
|
||||
FetchDevicesByRoomIdEvent({
|
||||
required this.unit,
|
||||
required this.roomId,
|
||||
});
|
||||
|
||||
// Adding properties for Equatable to compare
|
||||
@override
|
||||
List<Object> get props => [unit, roomId];
|
||||
}
|
||||
|
||||
|
||||
class LoadingDeviceInfo extends SosEvent {
|
||||
DeviceInfoModel deviceInfo;
|
||||
LoadingDeviceInfo({required this.deviceInfo});
|
||||
DeviceInfoModel deviceInfo;
|
||||
LoadingDeviceInfo({required this.deviceInfo});
|
||||
|
||||
@override
|
||||
List<Object> get props => [deviceInfo];
|
||||
|
@ -12,12 +12,8 @@ class SosState extends Equatable {
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SosInitialState extends SosState {}
|
||||
|
||||
class SosLoadingState extends SosState {}
|
||||
|
||||
|
||||
|
||||
class SaveState extends SosState {}
|
||||
|
||||
class LoadingSosDeviceInfo extends SosState {
|
||||
|
@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for
|
||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
|
||||
version: 1.0.8+41
|
||||
version: 1.0.9+42
|
||||
|
||||
environment:
|
||||
sdk: ">=3.0.6 <4.0.0"
|
||||
|
Reference in New Issue
Block a user