mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-03-11 08:41:44 +00:00
Compare commits
45 Commits
SP-1190
...
SP-1397-FE
| Author | SHA1 | Date | |
|---|---|---|---|
| f2412aa867 | |||
| e4768c95aa | |||
| f25b4dbf6d | |||
| 9eff9ab371 | |||
| a2e68d6194 | |||
| 94c94b170f | |||
| 253cf15559 | |||
| 443eea9421 | |||
| 87a2c08f64 | |||
| dd66e7c747 | |||
| 7af61d2f65 | |||
| f37eacb0ee | |||
| c7dcc297aa | |||
| aefe5ad081 | |||
| 8d9af8519d | |||
| b1d52937c9 | |||
| 5fedf37421 | |||
| ccde857c29 | |||
| b2a8086e0e | |||
| 408e78962c | |||
| dcdbc02ca0 | |||
| 31025e9176 | |||
| 8219de6821 | |||
| fbdf3817ab | |||
| 17422edd0d | |||
| 4c8f2c72df | |||
| fb867e5df3 | |||
| 9472390284 | |||
| 731ba0f3d6 | |||
| 56407c6426 | |||
| 02d61ca0bb | |||
| 99ee4b9878 | |||
| 19edd0a275 | |||
| ef5e7c3154 | |||
| 80dd0f696f | |||
| a64a41548f | |||
| 0d50aa68fa | |||
| 88aac86b10 | |||
| 0673548745 | |||
| c2fc8fa0ae | |||
| cbf10bbf78 | |||
| d95588ce84 | |||
| 7e2e591d71 | |||
| 2ec81bda9c | |||
| 3b0f51473c |
2
.env.dev
2
.env.dev
@ -1,3 +1,5 @@
|
|||||||
ENV_NAME=development
|
ENV_NAME=development
|
||||||
BASE_URL=https://syncrow-dev.azurewebsites.net
|
BASE_URL=https://syncrow-dev.azurewebsites.net
|
||||||
PROJECT_ID=0e62577c-06fa-41b9-8a92-99a21fbaf51c
|
PROJECT_ID=0e62577c-06fa-41b9-8a92-99a21fbaf51c
|
||||||
|
CLIENT_ID=c024573d191a327ce74db7d4502fdc29
|
||||||
|
CLIENT_SECRET=fec6ccbc33664f94a3b84a45c7cceef3f3ebd1613ef4307db8946ede530cd1ed
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -42,3 +42,4 @@ app.*.map.json
|
|||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
/android/app/.cxx/
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/login_with_email_model.dart';
|
import 'package:syncrow_app/features/auth/model/login_with_email_model.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/signup_model.dart';
|
import 'package:syncrow_app/features/auth/model/signup_model.dart';
|
||||||
@ -217,9 +218,22 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
signUp() async {
|
signUp() async {
|
||||||
emit(AuthLoginLoading());
|
emit(AuthLoginLoading());
|
||||||
final response;
|
final response;
|
||||||
|
|
||||||
|
final clientId = dotenv.env['CLIENT_ID'] ?? '';
|
||||||
|
final clientSecret = dotenv.env['CLIENT_SECRET'] ?? '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> userFullName = fullName.split(' ');
|
List<String> userFullName = fullName.split(' ');
|
||||||
|
|
||||||
|
final clientToken = await AuthenticationAPI.fetchClientToken(
|
||||||
|
clientId: clientId,
|
||||||
|
clientSecret: clientSecret,
|
||||||
|
);
|
||||||
|
|
||||||
|
final accessToken = clientToken['accessToken'];
|
||||||
|
|
||||||
response = await AuthenticationAPI.signUp(
|
response = await AuthenticationAPI.signUp(
|
||||||
|
accessToken: accessToken,
|
||||||
model: SignUpModel(
|
model: SignUpModel(
|
||||||
hasAcceptedAppAgreement: true,
|
hasAcceptedAppAgreement: true,
|
||||||
email: email.toLowerCase(),
|
email: email.toLowerCase(),
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/curtain_bloc/curtain_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/curtain_bloc/curtain_event.dart';
|
||||||
@ -31,6 +32,7 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
on<InitialWizardEvent>(_fetchWizardStatus);
|
on<InitialWizardEvent>(_fetchWizardStatus);
|
||||||
on<GroupAllOffEvent>(_groupAllOff);
|
on<GroupAllOffEvent>(_groupAllOff);
|
||||||
on<GroupAllOnEvent>(_groupAllOn);
|
on<GroupAllOnEvent>(_groupAllOn);
|
||||||
|
on<UpdateCurtainEvent>(_updateCurtain);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onOpenCurtain(
|
Future<void> _onOpenCurtain(
|
||||||
@ -162,7 +164,10 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
void _fetchStatus(InitCurtain event, Emitter<CurtainState> emit) async {
|
void _fetchStatus(InitCurtain event, Emitter<CurtainState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(CurtainLoadingState());
|
emit(CurtainLoadingState());
|
||||||
|
_listenToChanges(curtainId);
|
||||||
|
|
||||||
var response = await DevicesAPI.getDeviceStatus(curtainId);
|
var response = await DevicesAPI.getDeviceStatus(curtainId);
|
||||||
|
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -170,7 +175,6 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
openPercentage = double.tryParse(statusModelList[1].value.toString())!;
|
openPercentage = double.tryParse(statusModelList[1].value.toString())!;
|
||||||
curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
||||||
blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
||||||
// _listenToChanges();
|
|
||||||
emit(CurtainsOpening(
|
emit(CurtainsOpening(
|
||||||
curtainWidth: curtainWidth,
|
curtainWidth: curtainWidth,
|
||||||
blindHeight: blindHeight,
|
blindHeight: blindHeight,
|
||||||
@ -181,38 +185,76 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Real-time Database
|
|
||||||
// StreamSubscription<DatabaseEvent>? _streamSubscription;
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
// Timer? _timer;
|
|
||||||
// void _listenToChanges() {
|
void _listenToChanges(curtainId) {
|
||||||
|
try {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$curtainId');
|
||||||
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
|
_streamSubscription = stream.listen((DatabaseEvent event) {
|
||||||
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
|
usersMap['status'].forEach((element) {
|
||||||
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
|
});
|
||||||
|
openPercentage = double.tryParse(statusList[1].value.toString())!;
|
||||||
|
curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
||||||
|
blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
||||||
|
add(UpdateCurtainEvent());
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// _listenToChanges(curtainId) {
|
||||||
// try {
|
// try {
|
||||||
// _streamSubscription?.cancel();
|
// print('curtainId=$curtainId');
|
||||||
// DatabaseReference ref =
|
// DatabaseReference ref =
|
||||||
// FirebaseDatabase.instance.ref('device-status/$curtainId');
|
// FirebaseDatabase.instance.ref('device-status/$curtainId');
|
||||||
// Stream<DatabaseEvent> stream = ref.onValue;
|
// Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
// _streamSubscription = stream.listen((DatabaseEvent event) async {
|
// stream.listen((DatabaseEvent event) async {
|
||||||
// if (_timer != null) {
|
// if (_timer != null) {
|
||||||
// await Future.delayed(const Duration(seconds: 2));
|
// await Future.delayed(const Duration(seconds: 2));
|
||||||
// }
|
// }
|
||||||
// Map<dynamic, dynamic> usersMap =
|
// Map<dynamic, dynamic> usersMap =
|
||||||
// event.snapshot.value as Map<dynamic, dynamic>;
|
// event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
// List<StatusModel> statusList = [];
|
// List<StatusModel> statusModelList = [];
|
||||||
// usersMap['status'].forEach((element) {
|
// for (var status in usersMap['status']) {
|
||||||
// statusList
|
// statusModelList.add(StatusModel.fromJson(status));
|
||||||
// .add(StatusModel(code: element['code'], value: element['value']));
|
// print('statusModelList==${statusModelList}');
|
||||||
// });
|
// }
|
||||||
// deviceStatus = CurtainModel.fromJson(statusList);
|
|
||||||
// if (!isClosed) {}
|
// openPercentage = double.tryParse(statusModelList[1].value.toString())!;
|
||||||
|
// curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
||||||
|
// blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
||||||
|
// add(UpdateCurtainEvent());
|
||||||
// });
|
// });
|
||||||
// } catch (_) {}
|
// } catch (_) {}
|
||||||
// }
|
// }
|
||||||
// @override
|
|
||||||
// Future<void> close() async {
|
_updateCurtain(UpdateCurtainEvent event, Emitter<CurtainState> emit) {
|
||||||
// _streamSubscription?.cancel();
|
curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
||||||
// _streamSubscription = null;
|
blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
||||||
// return super.close();
|
emit(CurtainsOpening(
|
||||||
// }
|
curtainWidth: curtainWidth,
|
||||||
|
blindHeight: blindHeight,
|
||||||
|
openPercentage: openPercentage,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
List<GroupCurtainModel> groupList = [];
|
List<GroupCurtainModel> groupList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|||||||
@ -33,6 +33,7 @@ class InitCurtain extends CurtainEvent {}
|
|||||||
class PauseCurtain extends CurtainEvent {}
|
class PauseCurtain extends CurtainEvent {}
|
||||||
class useCurtainEvent extends CurtainEvent {}
|
class useCurtainEvent extends CurtainEvent {}
|
||||||
class InitialWizardEvent extends CurtainEvent {}
|
class InitialWizardEvent extends CurtainEvent {}
|
||||||
|
class UpdateCurtainEvent extends CurtainEvent {}
|
||||||
|
|
||||||
|
|
||||||
class ChangeFirstWizardSwitchStatusEvent extends CurtainEvent {
|
class ChangeFirstWizardSwitchStatusEvent extends CurtainEvent {
|
||||||
|
|||||||
@ -463,7 +463,15 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
projectId: project?.uuid ?? TempConst.projectIdDev);
|
projectId: project?.uuid ?? TempConst.projectIdDev);
|
||||||
allDevices = devices;
|
allDevices = devices;
|
||||||
for (var deviceId in allDevices) {
|
for (var deviceId in allDevices) {
|
||||||
if (deviceId.type == "3G" || deviceId.type == "AC") {
|
if (deviceId.type == "3G" ||
|
||||||
|
deviceId.type == "2G" ||
|
||||||
|
deviceId.type == "1G" ||
|
||||||
|
deviceId.type == "3GT" ||
|
||||||
|
deviceId.type == "2GT" ||
|
||||||
|
deviceId.type == "1GT" ||
|
||||||
|
deviceId.type == "WH" ||
|
||||||
|
deviceId.type == "CUR" ||
|
||||||
|
deviceId.type == "AC") {
|
||||||
_listenToChanges(deviceId.uuid);
|
_listenToChanges(deviceId.uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,7 +569,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<void> towGangToggle(
|
Future<void> towGangToggle(
|
||||||
DeviceControlModel control, String deviceUuid) async {
|
DeviceControlModel control, String deviceUuid) async {
|
||||||
emit(SwitchControlLoading(code: control.code));
|
emit(SwitchControlLoading(code: control.code));
|
||||||
@ -653,7 +660,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
code: 'switch_1', value: toggledValue, deviceId: deviceUuid);
|
code: 'switch_1', value: toggledValue, deviceId: deviceUuid);
|
||||||
final response =
|
final response =
|
||||||
await DevicesAPI.controlDevice(controlRequest, deviceUuid);
|
await DevicesAPI.controlDevice(controlRequest, deviceUuid);
|
||||||
print(response);
|
|
||||||
if (response['result'] != true) {
|
if (response['result'] != true) {
|
||||||
throw Exception('Failed to toggle switch_1');
|
throw Exception('Failed to toggle switch_1');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_state.dart';
|
||||||
@ -40,7 +41,7 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
|||||||
);
|
);
|
||||||
emit(UpdateState(doorSensor: deviceStatus));
|
emit(UpdateState(doorSensor: deviceStatus));
|
||||||
Future.delayed(const Duration(milliseconds: 500));
|
Future.delayed(const Duration(milliseconds: 500));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(DoorSensorFailedState(errorMessage: e.toString()));
|
emit(DoorSensorFailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
@ -136,41 +137,42 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
|||||||
String errorMessage = errorData['message'];
|
String errorMessage = errorData['message'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// real-time database
|
// real-time database
|
||||||
// Timer? _timer;
|
Timer? _timer;
|
||||||
// StreamSubscription<DatabaseEvent>? _streamSubscription;
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
// void _listenToChanges() {
|
void _listenToChanges() {
|
||||||
// try {
|
try {
|
||||||
// _streamSubscription?.cancel();
|
_streamSubscription?.cancel();
|
||||||
// DatabaseReference ref =
|
DatabaseReference ref =
|
||||||
// FirebaseDatabase.instance.ref('device-status/$DSId');
|
FirebaseDatabase.instance.ref('device-status/$DSId');
|
||||||
// Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
// _streamSubscription = stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
// if (_timer != null) {
|
if (_timer != null) {
|
||||||
// await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
// }
|
}
|
||||||
// Map<dynamic, dynamic> usersMap =
|
Map<dynamic, dynamic> usersMap =
|
||||||
// event.snapshot.value as Map<dynamic, dynamic>;
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
// List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
// usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
// statusList
|
statusList
|
||||||
// .add(StatusModel(code: element['code'], value: element['value']));
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
// });
|
});
|
||||||
// deviceStatus = DoorSensorModel.fromJson(statusList);
|
deviceStatus = DoorSensorModel.fromJson(statusList);
|
||||||
// if (!isClosed) {
|
if (!isClosed) {
|
||||||
// add(
|
add(
|
||||||
// DoorSensorSwitch(switchD: deviceStatus.doorContactState),
|
DoorSensorSwitch(switchD: deviceStatus.doorContactState),
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// } catch (_) {}
|
} catch (_) {}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// @override
|
@override
|
||||||
// Future<void> close() async {
|
Future<void> close() async {
|
||||||
// _streamSubscription?.cancel();
|
_streamSubscription?.cancel();
|
||||||
// _streamSubscription = null;
|
_streamSubscription = null;
|
||||||
// return super.close();
|
return super.close();
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/garage_door_bloc/garage_door_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/garage_door_bloc/garage_door_event.dart';
|
||||||
@ -41,6 +42,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
|||||||
on<ChangeFirstWizardSwitchStatusEvent>(_changeFirstWizardSwitch);
|
on<ChangeFirstWizardSwitchStatusEvent>(_changeFirstWizardSwitch);
|
||||||
on<ToggleAlarmEvent>(_toggleAlarmEvent);
|
on<ToggleAlarmEvent>(_toggleAlarmEvent);
|
||||||
on<DeleteScheduleEvent>(deleteSchedule);
|
on<DeleteScheduleEvent>(deleteSchedule);
|
||||||
|
|
||||||
|
on<UpdateStateEvent>(_updateState);
|
||||||
}
|
}
|
||||||
void _onClose(OnClose event, Emitter<GarageDoorSensorState> emit) {
|
void _onClose(OnClose event, Emitter<GarageDoorSensorState> emit) {
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
@ -79,7 +82,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
|||||||
toggleDoor = deviceStatus.switch1;
|
toggleDoor = deviceStatus.switch1;
|
||||||
emit(UpdateState(garageSensor: deviceStatus));
|
emit(UpdateState(garageSensor: deviceStatus));
|
||||||
Future.delayed(const Duration(milliseconds: 500));
|
Future.delayed(const Duration(milliseconds: 500));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(GarageDoorFailedState(errorMessage: e.toString()));
|
emit(GarageDoorFailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
@ -179,39 +182,57 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorSensorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Real-time db
|
// Real-time db
|
||||||
// StreamSubscription<DatabaseEvent>? _streamSubscription;
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
// void _listenToChanges() {
|
void _listenToChanges() {
|
||||||
// try {
|
try {
|
||||||
// _streamSubscription?.cancel();
|
_streamSubscription?.cancel();
|
||||||
// DatabaseReference ref =
|
DatabaseReference ref =
|
||||||
// FirebaseDatabase.instance.ref('device-status/$GDId');
|
FirebaseDatabase.instance.ref('device-status/$GDId');
|
||||||
// Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
// _streamSubscription = stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
// if (_timer != null) {
|
if (_timer != null) {
|
||||||
// await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
// }
|
}
|
||||||
// Map<dynamic, dynamic> usersMap =
|
|
||||||
// event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
// List<StatusModel> statusList = [];
|
|
||||||
// usersMap['status'].forEach((element) {
|
|
||||||
// statusList
|
|
||||||
// .add(StatusModel(code: element['code'], value: element['value']));
|
|
||||||
// });
|
|
||||||
// deviceStatus = GarageDoorModel.fromJson(statusList);
|
|
||||||
// // if (!isClosed) {
|
|
||||||
// // add(ToggleSelectedEvent());
|
|
||||||
// // }
|
|
||||||
// });
|
|
||||||
// } catch (_) {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @override
|
if (event.snapshot.value != null) {
|
||||||
// Future<void> close() async {
|
Map<dynamic, dynamic> usersMap =
|
||||||
// _streamSubscription?.cancel();
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
// _streamSubscription = null;
|
List<StatusModel> statusList = [];
|
||||||
// return super.close();
|
|
||||||
// }
|
usersMap['status'].forEach((element) {
|
||||||
|
statusList.add(
|
||||||
|
StatusModel(code: element['code'], value: element['value']));
|
||||||
|
});
|
||||||
|
deviceStatus.tr_timecon = statusList
|
||||||
|
.firstWhere((status) => status.code == "tr_timecon",
|
||||||
|
orElse: () => StatusModel(code: "tr_timecon", value: 0))
|
||||||
|
.value as int;
|
||||||
|
|
||||||
|
deviceStatus.switch1 = statusList
|
||||||
|
.firstWhere((status) => status.code == "switch_1",
|
||||||
|
orElse: () => StatusModel(code: "switch_1", value: false))
|
||||||
|
.value as bool;
|
||||||
|
secondSelected = deviceStatus.tr_timecon;
|
||||||
|
toggleDoor = deviceStatus.switch1;
|
||||||
|
add(UpdateStateEvent());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _updateState(
|
||||||
|
UpdateStateEvent event, Emitter<GarageDoorSensorState> emit) async {
|
||||||
|
emit(GarageDoorLoadingState());
|
||||||
|
emit(UpdateState(garageSensor: deviceStatus));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
List<Map<String, String>> days = [
|
List<Map<String, String>> days = [
|
||||||
{"day": "Sun", "key": "Sun"},
|
{"day": "Sun", "key": "Sun"},
|
||||||
|
|||||||
@ -109,6 +109,8 @@ class GetScheduleEvent extends GarageDoorEvent {}
|
|||||||
|
|
||||||
class ScheduleSaveapp extends GarageDoorEvent {}
|
class ScheduleSaveapp extends GarageDoorEvent {}
|
||||||
|
|
||||||
|
class UpdateStateEvent extends GarageDoorEvent {}
|
||||||
|
|
||||||
class ToggleScheduleEvent extends GarageDoorEvent {
|
class ToggleScheduleEvent extends GarageDoorEvent {
|
||||||
final String id;
|
final String id;
|
||||||
final bool toggle;
|
final bool toggle;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/one_gang_bloc/one_gang_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/one_gang_bloc/one_gang_state.dart';
|
||||||
@ -60,48 +61,46 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = OneGangModel.fromJson(statusModelList);
|
deviceStatus = OneGangModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(oneGangModel: deviceStatus));
|
emit(UpdateState(oneGangModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges(oneGangId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Real-time db
|
// Real-time db
|
||||||
// StreamSubscription<DatabaseEvent>? _streamSubscription;
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
// void _listenToChanges() {
|
void _listenToChanges(String id) {
|
||||||
// try {
|
try {
|
||||||
// _streamSubscription?.cancel();
|
_streamSubscription?.cancel();
|
||||||
// DatabaseReference ref =
|
DatabaseReference ref =
|
||||||
// FirebaseDatabase.instance.ref('device-status/$oneGangId');
|
FirebaseDatabase.instance.ref('device-status/$id');
|
||||||
// Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
// _streamSubscription = stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) {
|
||||||
// if (_timer != null) {
|
Map<dynamic, dynamic> usersMap =
|
||||||
// await Future.delayed(const Duration(seconds: 2));
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
// }
|
List<StatusModel> statusList = [];
|
||||||
// Map<dynamic, dynamic> usersMap =
|
|
||||||
// event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
// List<StatusModel> statusList = [];
|
|
||||||
// usersMap['status'].forEach((element) {
|
|
||||||
// statusList
|
|
||||||
// .add(StatusModel(code: element['code'], value: element['value']));
|
|
||||||
// });
|
|
||||||
// deviceStatus = OneGangModel.fromJson(statusList);
|
|
||||||
// if (!isClosed) {
|
|
||||||
// add(OneGangUpdated());
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// } catch (_) {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @override
|
usersMap['status'].forEach((element) {
|
||||||
// Future<void> close() async {
|
statusList
|
||||||
// _streamSubscription?.cancel();
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
// _streamSubscription = null;
|
});
|
||||||
// return super.close();
|
deviceStatus = OneGangModel.fromJson(statusList);
|
||||||
// }
|
add(OneGangUpdated());
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
_oneGangUpdated(OneGangUpdated event, Emitter<OneGangState> emit) {
|
_oneGangUpdated(OneGangUpdated event, Emitter<OneGangState> emit) {
|
||||||
|
emit(LoadingInitialState());
|
||||||
emit(UpdateState(oneGangModel: deviceStatus));
|
emit(UpdateState(oneGangModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
@ -63,39 +64,54 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
}
|
}
|
||||||
deviceStatus = OneTouchModel.fromJson(statusModelList);
|
deviceStatus = OneTouchModel.fromJson(statusModelList);
|
||||||
|
_listenToChanges(oneTouchId);
|
||||||
|
|
||||||
emit(UpdateState(oneTouchModel: deviceStatus));
|
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||||
// _listenToChanges();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Real-time db
|
|
||||||
// _listenToChanges() {
|
|
||||||
// try {
|
|
||||||
// DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$oneTouchId');
|
|
||||||
// Stream<DatabaseEvent> stream = ref.onValue;
|
|
||||||
|
|
||||||
// stream.listen((DatabaseEvent event) async {
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
// if (_timer != null) {
|
void _listenToChanges(String id) {
|
||||||
// await Future.delayed(const Duration(seconds: 2));
|
try {
|
||||||
// }
|
_streamSubscription?.cancel();
|
||||||
// Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
DatabaseReference ref =
|
||||||
// List<StatusModel> statusList = [];
|
FirebaseDatabase.instance.ref('device-status/$id');
|
||||||
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
// usersMap['status'].forEach((element) {
|
_streamSubscription = stream.listen((DatabaseEvent event) {
|
||||||
// statusList.add(StatusModel(code: element['code'], value: element['value']));
|
if (event.snapshot.value != null) {
|
||||||
// });
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
// deviceStatus = OneTouchModel.fromJson(statusList);
|
usersMap['status'].forEach((element) {
|
||||||
// if (!isClosed) {
|
statusList.add(
|
||||||
// add(OneTouchUpdated());
|
StatusModel(code: element['code'], value: element['value']));
|
||||||
// }
|
});
|
||||||
// });
|
var switchStatus = statusList.firstWhere(
|
||||||
// } catch (_) {}
|
(status) => status.code == "switch_1",
|
||||||
// }
|
orElse: () => StatusModel(code: "switch_1", value: false));
|
||||||
|
|
||||||
|
deviceStatus.firstSwitch = switchStatus.value as bool;
|
||||||
|
add(OneTouchUpdated());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (_) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
_oneTouchUpdated(OneTouchUpdated event, Emitter<OneTouchState> emit) {
|
_oneTouchUpdated(OneTouchUpdated event, Emitter<OneTouchState> emit) {
|
||||||
|
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||||
emit(UpdateState(oneTouchModel: deviceStatus));
|
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/three_touch_bloc/three_touch_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/three_touch_bloc/three_touch_event.dart';
|
||||||
@ -37,7 +38,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
List<GroupThreeTouchModel> groupThreeTouchList = [];
|
List<GroupThreeTouchModel> groupThreeTouchList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|
||||||
ThreeTouchBloc({required this.threeTouchId, required this.switchCode}) : super(InitialState()) {
|
ThreeTouchBloc({required this.threeTouchId, required this.switchCode})
|
||||||
|
: super(InitialState()) {
|
||||||
on<InitialEvent>(_fetchThreeTouchStatus);
|
on<InitialEvent>(_fetchThreeTouchStatus);
|
||||||
on<ThreeTouchUpdated>(_threeTouchUpdated);
|
on<ThreeTouchUpdated>(_threeTouchUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -62,7 +64,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
on<ChangeStatusEvent>(_changeStatus);
|
on<ChangeStatusEvent>(_changeStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchThreeTouchStatus(InitialEvent event, Emitter<ThreeTouchState> emit) async {
|
void _fetchThreeTouchStatus(
|
||||||
|
InitialEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
threeTouchGroup = event.groupScreen;
|
threeTouchGroup = event.groupScreen;
|
||||||
@ -74,7 +77,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '3GT');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '3GT');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
var response =
|
||||||
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -91,13 +95,16 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
|
|
||||||
if (groupThreeTouchList.isNotEmpty) {
|
if (groupThreeTouchList.isNotEmpty) {
|
||||||
groupThreeTouchList.firstWhere((element) {
|
groupThreeTouchList.firstWhere((element) {
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesOn = false;
|
allSwitchesOn = false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn));
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn));
|
||||||
} else {
|
} else {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
@ -106,7 +113,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = ThreeTouchModel.fromJson(statusModelList);
|
deviceStatus = ThreeTouchModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
@ -114,35 +121,39 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _listenToChanges() {
|
_listenToChanges() {
|
||||||
// try {
|
try {
|
||||||
// DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeTouchId');
|
DatabaseReference ref =
|
||||||
// Stream<DatabaseEvent> stream = ref.onValue;
|
FirebaseDatabase.instance.ref('device-status/$threeTouchId');
|
||||||
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
// stream.listen((DatabaseEvent event) async {
|
stream.listen((DatabaseEvent event) async {
|
||||||
// if (_timer != null) {
|
if (_timer != null) {
|
||||||
// await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
// }
|
}
|
||||||
// Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
Map<dynamic, dynamic> usersMap =
|
||||||
// List<StatusModel> statusList = [];
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
// usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
// statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList
|
||||||
// });
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
|
});
|
||||||
|
|
||||||
// deviceStatus = ThreeTouchModel.fromJson(statusList);
|
deviceStatus = ThreeTouchModel.fromJson(statusList);
|
||||||
// if (!isClosed) {
|
if (!isClosed) {
|
||||||
// add(ThreeTouchUpdated());
|
add(ThreeTouchUpdated());
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// } catch (_) {}
|
} catch (_) {}
|
||||||
// }
|
}
|
||||||
|
|
||||||
_threeTouchUpdated(ThreeTouchUpdated event, Emitter<ThreeTouchState> emit) {
|
_threeTouchUpdated(ThreeTouchUpdated event, Emitter<ThreeTouchState> emit) {
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
void _changeFirstSwitch(
|
||||||
|
ChangeFirstSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeTouchGroup) {
|
if (threeTouchGroup) {
|
||||||
@ -151,11 +162,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.firstSwitch = !event.value;
|
element.firstSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList,
|
||||||
|
allSwitches: allSwitchesValue));
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
@ -182,8 +197,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondSwitch(
|
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event,
|
||||||
ChangeSecondSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeTouchGroup) {
|
if (threeTouchGroup) {
|
||||||
@ -192,11 +207,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.secondSwitch = !event.value;
|
element.secondSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList,
|
||||||
|
allSwitches: allSwitchesValue));
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.secondSwitch = !event.value;
|
deviceStatus.secondSwitch = !event.value;
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
@ -222,7 +241,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
void _changeThirdSwitch(
|
||||||
|
ChangeThirdSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeTouchGroup) {
|
if (threeTouchGroup) {
|
||||||
@ -231,11 +251,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.thirdSwitch = !event.value;
|
element.thirdSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
if (!element.firstSwitch ||
|
||||||
|
!element.secondSwitch ||
|
||||||
|
!element.thirdSwitch) {
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList,
|
||||||
|
allSwitches: allSwitchesValue));
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.thirdSwitch = !event.value;
|
deviceStatus.thirdSwitch = !event.value;
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
@ -274,15 +298,21 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_3',
|
||||||
|
value: deviceStatus.thirdSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -308,15 +338,21 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
deviceId: threeTouchId,
|
||||||
|
code: 'switch_3',
|
||||||
|
value: deviceStatus.thirdSwitch),
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -338,8 +374,10 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
groupThreeTouchList[i].secondSwitch = true;
|
groupThreeTouchList[i].secondSwitch = true;
|
||||||
groupThreeTouchList[i].thirdSwitch = true;
|
groupThreeTouchList[i].thirdSwitch = true;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: true));
|
emit(UpdateGroupState(
|
||||||
List<String> allDeviceIds = groupThreeTouchList.map((device) => device.deviceId).toList();
|
threeTouchList: groupThreeTouchList, allSwitches: true));
|
||||||
|
List<String> allDeviceIds =
|
||||||
|
groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: allDeviceIds,
|
devicesUuid: allDeviceIds,
|
||||||
@ -368,7 +406,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _groupAllOff(GroupAllOffEvent event, Emitter<ThreeTouchState> emit) async {
|
void _groupAllOff(
|
||||||
|
GroupAllOffEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < groupThreeTouchList.length; i++) {
|
for (int i = 0; i < groupThreeTouchList.length; i++) {
|
||||||
@ -376,8 +415,10 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
groupThreeTouchList[i].secondSwitch = false;
|
groupThreeTouchList[i].secondSwitch = false;
|
||||||
groupThreeTouchList[i].thirdSwitch = false;
|
groupThreeTouchList[i].thirdSwitch = false;
|
||||||
}
|
}
|
||||||
List<String> allDeviceIds = groupThreeTouchList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: false));
|
groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||||
|
emit(UpdateGroupState(
|
||||||
|
threeTouchList: groupThreeTouchList, allSwitches: false));
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: allDeviceIds,
|
devicesUuid: allDeviceIds,
|
||||||
@ -406,17 +447,20 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(ChangeSlidingSegment event, Emitter<ThreeTouchState> emit) async {
|
void _changeSliding(
|
||||||
|
ChangeSlidingSegment event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(SetCounterValue event, Emitter<ThreeTouchState> emit) async {
|
void _setCounterValue(
|
||||||
|
SetCounterValue event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: threeTouchId, code: event.deviceCode, value: seconds),
|
DeviceControlModel(
|
||||||
|
deviceId: threeTouchId, code: event.deviceCode, value: seconds),
|
||||||
threeTouchId);
|
threeTouchId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -443,7 +487,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(GetCounterEvent event, Emitter<ThreeTouchState> emit) async {
|
void _getCounterValue(
|
||||||
|
GetCounterEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
||||||
@ -553,7 +598,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
deviceId: threeTouchId,
|
deviceId: threeTouchId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
listSchedule =
|
||||||
|
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -564,12 +610,13 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds =
|
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleChange(ToggleScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
Future toggleChange(
|
||||||
|
ToggleScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -588,7 +635,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
Future deleteSchedule(
|
||||||
|
DeleteScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -608,13 +656,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<ThreeTouchState> emit) {
|
void toggleSelectedIndex(
|
||||||
|
ToggleSelectedEvent event, Emitter<ThreeTouchState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<ThreeTouchState> emit) {
|
void toggleCreateSchedule(
|
||||||
|
ToggleCreateScheduleEvent event, Emitter<ThreeTouchState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -632,7 +682,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
String statusSelected = '';
|
String statusSelected = '';
|
||||||
String optionSelected = '';
|
String optionSelected = '';
|
||||||
|
|
||||||
Future<void> _changeStatus(ChangeStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
Future<void> _changeStatus(
|
||||||
|
ChangeStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final Map<String, Map<String, String>> controlMap = {
|
final Map<String, Map<String, String>> controlMap = {
|
||||||
@ -666,11 +717,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
||||||
if (selectedControl != null) {
|
if (selectedControl != null) {
|
||||||
await DevicesAPI.controlDevice(
|
await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: threeTouchId, code: optionSelected, value: selectedControl),
|
DeviceControlModel(
|
||||||
|
deviceId: threeTouchId,
|
||||||
|
code: optionSelected,
|
||||||
|
value: selectedControl),
|
||||||
threeTouchId,
|
threeTouchId,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
emit(const FailedState(error: 'Invalid statusSelected or optionSelected'));
|
emit(const FailedState(
|
||||||
|
error: 'Invalid statusSelected or optionSelected'));
|
||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/two_gang_bloc/two_gang_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/two_gang_bloc/two_gang_event.dart';
|
||||||
@ -34,7 +35,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
bool createSchedule = false;
|
bool createSchedule = false;
|
||||||
List<ScheduleModel> listSchedule = [];
|
List<ScheduleModel> listSchedule = [];
|
||||||
|
|
||||||
TwoGangBloc({required this.twoGangId, required this.switchCode}) : super(InitialState()) {
|
TwoGangBloc({required this.twoGangId, required this.switchCode})
|
||||||
|
: super(InitialState()) {
|
||||||
on<InitialEvent>(_fetchTwoGangStatus);
|
on<InitialEvent>(_fetchTwoGangStatus);
|
||||||
on<TwoGangUpdated>(_twoGangUpdated);
|
on<TwoGangUpdated>(_twoGangUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -64,13 +66,15 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
int selectedTabIndex = 0;
|
int selectedTabIndex = 0;
|
||||||
|
|
||||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<TwoGangState> emit) {
|
void toggleSelectedIndex(
|
||||||
|
ToggleSelectedEvent event, Emitter<TwoGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<TwoGangState> emit) {
|
void toggleCreateSchedule(
|
||||||
|
ToggleCreateScheduleEvent event, Emitter<TwoGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -78,7 +82,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
emit(UpdateCreateScheduleState(createSchedule));
|
emit(UpdateCreateScheduleState(createSchedule));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchTwoGangStatus(InitialEvent event, Emitter<TwoGangState> emit) async {
|
void _fetchTwoGangStatus(
|
||||||
|
InitialEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(twoGangId);
|
var response = await DevicesAPI.getDeviceStatus(twoGangId);
|
||||||
@ -88,42 +93,50 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = TwoGangModel.fromJson(statusModelList);
|
deviceStatus = TwoGangModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(twoGangModel: deviceStatus));
|
emit(UpdateState(twoGangModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges(twoGangId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _listenToChanges() {
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
// try {
|
void _listenToChanges(String id) {
|
||||||
// DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoGangId');
|
try {
|
||||||
// Stream<DatabaseEvent> stream = ref.onValue;
|
_streamSubscription?.cancel();
|
||||||
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$id');
|
||||||
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
_streamSubscription = stream.listen((DatabaseEvent event) {
|
||||||
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
// stream.listen((DatabaseEvent event) async {
|
usersMap['status'].forEach((element) {
|
||||||
// if (_timer != null) {
|
statusList
|
||||||
// await Future.delayed(const Duration(seconds: 2));
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
// }
|
});
|
||||||
// Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
deviceStatus = TwoGangModel.fromJson(statusList);
|
||||||
// List<StatusModel> statusList = [];
|
add(TwoGangUpdated());
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
// usersMap['status'].forEach((element) {
|
@override
|
||||||
// statusList.add(StatusModel(code: element['code'], value: element['value']));
|
Future<void> close() async {
|
||||||
// });
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
// deviceStatus = TwoGangModel.fromJson(statusList);
|
return super.close();
|
||||||
// if (!isClosed) {
|
}
|
||||||
// add(TwoGangUpdated());
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// } catch (_) {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
_twoGangUpdated(TwoGangUpdated event, Emitter<TwoGangState> emit) {
|
_twoGangUpdated(TwoGangUpdated event, Emitter<TwoGangState> emit) {
|
||||||
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
|
|
||||||
emit(UpdateState(twoGangModel: deviceStatus));
|
emit(UpdateState(twoGangModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
void _changeFirstSwitch(
|
||||||
|
ChangeFirstSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
@ -134,7 +147,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: twoGangId, code: 'switch_1', value: !event.value),
|
DeviceControlModel(
|
||||||
|
deviceId: twoGangId, code: 'switch_1', value: !event.value),
|
||||||
twoGangId);
|
twoGangId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -146,7 +160,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
void _changeSecondSwitch(
|
||||||
|
ChangeSecondSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.secondSwitch = !event.value;
|
deviceStatus.secondSwitch = !event.value;
|
||||||
@ -156,7 +171,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: twoGangId, code: 'switch_2', value: !event.value),
|
DeviceControlModel(
|
||||||
|
deviceId: twoGangId, code: 'switch_2', value: !event.value),
|
||||||
twoGangId);
|
twoGangId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -179,11 +195,15 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: twoGangId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
twoGangId),
|
twoGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: twoGangId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
twoGangId),
|
twoGangId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -206,11 +226,15 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
deviceId: twoGangId,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: deviceStatus.firstSwitch),
|
||||||
twoGangId),
|
twoGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
deviceId: twoGangId,
|
||||||
|
code: 'switch_2',
|
||||||
|
value: deviceStatus.secondSwitch),
|
||||||
twoGangId),
|
twoGangId),
|
||||||
]);
|
]);
|
||||||
if (response.every((element) => !element['success'])) {
|
if (response.every((element) => !element['success'])) {
|
||||||
@ -231,7 +255,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
groupTwoGangList[i].secondSwitch = true;
|
groupTwoGangList[i].secondSwitch = true;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true));
|
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true));
|
||||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -266,7 +291,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false));
|
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false));
|
||||||
|
|
||||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -291,17 +317,20 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(ChangeSlidingSegment event, Emitter<TwoGangState> emit) async {
|
void _changeSliding(
|
||||||
|
ChangeSlidingSegment event, Emitter<TwoGangState> emit) async {
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(SetCounterValue event, Emitter<TwoGangState> emit) async {
|
void _setCounterValue(
|
||||||
|
SetCounterValue event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: twoGangId, code: event.deviceCode, value: seconds),
|
DeviceControlModel(
|
||||||
|
deviceId: twoGangId, code: event.deviceCode, value: seconds),
|
||||||
twoGangId);
|
twoGangId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -326,7 +355,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(GetCounterEvent event, Emitter<TwoGangState> emit) async {
|
void _getCounterValue(
|
||||||
|
GetCounterEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
add(GetScheduleEvent());
|
add(GetScheduleEvent());
|
||||||
@ -434,7 +464,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
deviceId: twoGangId,
|
deviceId: twoGangId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
listSchedule =
|
||||||
|
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -445,12 +476,13 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds =
|
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleRepeat(ToggleScheduleEvent event, Emitter<TwoGangState> emit) async {
|
Future toggleRepeat(
|
||||||
|
ToggleScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -469,7 +501,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<TwoGangState> emit) async {
|
Future deleteSchedule(
|
||||||
|
DeleteScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -489,7 +522,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchTwoGangWizardStatus(InitialWizardEvent event, Emitter<TwoGangState> emit) async {
|
void _fetchTwoGangWizardStatus(
|
||||||
|
InitialWizardEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
devicesList = [];
|
devicesList = [];
|
||||||
@ -499,7 +533,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '2G');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '2G');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
var response =
|
||||||
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -522,15 +557,16 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstWizardSwitch(
|
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -543,9 +579,11 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||||
|
|
||||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: allDeviceIds,
|
devicesUuid: allDeviceIds,
|
||||||
@ -560,8 +598,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondWizardSwitch(
|
void _changeSecondWizardSwitch(ChangeSecondWizardSwitchStatusEvent event,
|
||||||
ChangeSecondWizardSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -573,9 +611,11 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||||
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_2',
|
code: 'switch_2',
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/two_touch_bloc/two_touch_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/two_touch_bloc/two_touch_event.dart';
|
||||||
@ -98,52 +99,61 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
deviceStatus = TwoTouchModel.fromJson(statusModelList);
|
deviceStatus = TwoTouchModel.fromJson(statusModelList);
|
||||||
emit(UpdateState(twoTouchModel: deviceStatus));
|
emit(UpdateState(twoTouchModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamSubscription<DatabaseEvent>? _streamSubscription;
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
|
|
||||||
// void _listenToChanges() {
|
void _listenToChanges() {
|
||||||
// try {
|
try {
|
||||||
// _streamSubscription?.cancel();
|
_streamSubscription?.cancel();
|
||||||
// DatabaseReference ref =
|
DatabaseReference ref =
|
||||||
// FirebaseDatabase.instance.ref('device-status/$twoTouchId');
|
FirebaseDatabase.instance.ref('device-status/$twoTouchId');
|
||||||
// Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
// _streamSubscription = stream.listen((DatabaseEvent event) async {
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
// if (_timer != null) {
|
if (_timer != null) {
|
||||||
// await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
// }
|
}
|
||||||
// Map<dynamic, dynamic> usersMap =
|
if (event.snapshot.value != null) {
|
||||||
// event.snapshot.value as Map<dynamic, dynamic>;
|
Map<dynamic, dynamic> usersMap =
|
||||||
// List<StatusModel> statusList = [];
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
// usersMap['status'].forEach((element) {
|
List<StatusModel> statusList = [];
|
||||||
// statusList
|
|
||||||
// .add(StatusModel(code: element['code'], value: element['value']));
|
|
||||||
// });
|
|
||||||
// print('=========${usersMap['status']}');
|
|
||||||
// deviceStatus = TwoTouchModel.fromJson(statusList);
|
|
||||||
// if (!isClosed) {
|
|
||||||
// add(TwoTouchUpdated());
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// } catch (_) {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @override
|
usersMap['status'].forEach((element) {
|
||||||
// Future<void> close() async {
|
statusList.add(
|
||||||
// _streamSubscription?.cancel();
|
StatusModel(code: element['code'], value: element['value']));
|
||||||
// _streamSubscription = null;
|
});
|
||||||
// return super.close();
|
var switch1Status = statusList.firstWhere(
|
||||||
// }
|
(status) => status.code == "switch_1",
|
||||||
|
orElse: () => StatusModel(code: "switch_1", value: false));
|
||||||
|
|
||||||
|
var switch2Status = statusList.firstWhere(
|
||||||
|
(status) => status.code == "switch_2",
|
||||||
|
orElse: () => StatusModel(code: "switch_2", value: false));
|
||||||
|
deviceStatus.firstSwitch = switch1Status.value as bool;
|
||||||
|
deviceStatus.secondSwitch = switch2Status.value as bool;
|
||||||
|
|
||||||
|
add(TwoTouchUpdated());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (_) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
_twoTouchUpdated(TwoTouchUpdated event, Emitter<TwoTouchState> emit) {
|
_twoTouchUpdated(TwoTouchUpdated event, Emitter<TwoTouchState> emit) {
|
||||||
|
emit(LoadingInitialState());
|
||||||
emit(UpdateState(twoTouchModel: deviceStatus));
|
emit(UpdateState(twoTouchModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
@ -73,7 +74,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
statusModelList,
|
statusModelList,
|
||||||
);
|
);
|
||||||
emit(UpdateState(whModel: deviceStatus));
|
emit(UpdateState(whModel: deviceStatus));
|
||||||
// _listenToChanges();
|
_listenToChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(WHFailedState(errorMessage: e.toString()));
|
emit(WHFailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
@ -81,41 +82,39 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//real-time db
|
//real-time db
|
||||||
// StreamSubscription<DatabaseEvent>? _streamSubscription;
|
StreamSubscription<DatabaseEvent>? _streamSubscription;
|
||||||
// void _listenToChanges() {
|
void _listenToChanges() {
|
||||||
// try {
|
try {
|
||||||
// _streamSubscription?.cancel();
|
_streamSubscription?.cancel();
|
||||||
// DatabaseReference ref =
|
DatabaseReference ref =
|
||||||
// FirebaseDatabase.instance.ref('device-status/$whId');
|
FirebaseDatabase.instance.ref('device-status/$whId');
|
||||||
// Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
// _streamSubscription = stream.listen((DatabaseEvent event) async {
|
|
||||||
// if (_timer != null) {
|
|
||||||
// await Future.delayed(const Duration(seconds: 2));
|
|
||||||
// }
|
|
||||||
// Map<dynamic, dynamic> usersMap =
|
|
||||||
// event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
// List<StatusModel> statusList = [];
|
|
||||||
// usersMap['status'].forEach((element) {
|
|
||||||
// statusList
|
|
||||||
// .add(StatusModel(code: element['code'], value: element['value']));
|
|
||||||
// });
|
|
||||||
// deviceStatus = WHModel.fromJson(statusList);
|
|
||||||
// if (!isClosed) {
|
|
||||||
// add(WaterHeaterUpdated());
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// } catch (_) {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// Future<void> close() async {
|
|
||||||
// _streamSubscription?.cancel();
|
|
||||||
// _streamSubscription = null;
|
|
||||||
// return super.close();
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
_streamSubscription = stream.listen((DatabaseEvent event) async {
|
||||||
|
if (_timer != null) {
|
||||||
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
}
|
||||||
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
List<StatusModel> statusList = [];
|
||||||
|
usersMap['status'].forEach((element) {
|
||||||
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
|
});
|
||||||
|
deviceStatus = WHModel.fromJson(statusList);
|
||||||
|
if (!isClosed) {
|
||||||
|
add(WaterHeaterUpdated());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
_streamSubscription?.cancel();
|
||||||
|
_streamSubscription = null;
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
_waterHeaterUpdated(
|
_waterHeaterUpdated(
|
||||||
WaterHeaterUpdated event, Emitter<WaterHeaterState> emit) async {
|
WaterHeaterUpdated event, Emitter<WaterHeaterState> emit) async {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/all_devices.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/all_devices.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/room_page.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/room_page.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/rooms_slider.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/rooms_slider.dart';
|
||||||
@ -15,7 +15,7 @@ import 'package:syncrow_app/utils/context_extension.dart';
|
|||||||
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||||
|
|
||||||
class DevicesViewBody extends StatelessWidget {
|
class DevicesViewBody extends StatelessWidget {
|
||||||
const DevicesViewBody({Key? key}) : super(key: key);
|
const DevicesViewBody({super.key});
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<HomeCubit, HomeState>(
|
return BlocBuilder<HomeCubit, HomeState>(
|
||||||
@ -80,10 +80,7 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(
|
const SceneView(pageType: true),
|
||||||
height: MediaQuery.of(context).size.height * 0.1,
|
|
||||||
child: const SceneView(pageType: true),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
const RoomsSlider(),
|
const RoomsSlider(),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -8,8 +8,7 @@ import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart'
|
|||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||||
|
|
||||||
class GarageList extends StatelessWidget {
|
class GarageList extends StatelessWidget {
|
||||||
const GarageList(
|
const GarageList({super.key, required this.garageList, required this.allSwitches});
|
||||||
{super.key, required this.garageList, required this.allSwitches});
|
|
||||||
|
|
||||||
final List<GroupGarageModel> garageList;
|
final List<GroupGarageModel> garageList;
|
||||||
final bool allSwitches;
|
final bool allSwitches;
|
||||||
@ -23,43 +22,42 @@ class GarageList extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
const BodySmall(text: 'All Lights'),
|
const BodySmall(text: 'All Garages'),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
DevicesDefaultSwitch(
|
DevicesDefaultSwitch(
|
||||||
off: 'OFF',
|
off: 'Close',
|
||||||
on: 'ON',
|
on: 'Open',
|
||||||
switchValue: allSwitches,
|
switchValue: allSwitches,
|
||||||
action: () {
|
action: () => BlocProvider.of<GarageDoorBloc>(context).add(
|
||||||
BlocProvider.of<GarageDoorBloc>(context)
|
GroupAllOnEvent(),
|
||||||
.add(GroupAllOnEvent());
|
),
|
||||||
},
|
secondAction: () => BlocProvider.of<GarageDoorBloc>(context).add(
|
||||||
secondAction: () {
|
GroupAllOffEvent(),
|
||||||
BlocProvider.of<GarageDoorBloc>(context)
|
),
|
||||||
.add(GroupAllOffEvent());
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
ListView.builder(
|
ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
padding: const EdgeInsets.all(0),
|
padding: EdgeInsetsDirectional.zero,
|
||||||
itemCount: garageList.length,
|
itemCount: garageList.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
final garageDoor = garageList[index];
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
BodySmall(text: garageList[index].deviceName),
|
BodySmall(text: garageDoor.deviceName),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
DevicesDefaultSwitch(
|
DevicesDefaultSwitch(
|
||||||
off: 'OFF',
|
off: 'Close',
|
||||||
on: 'ON',
|
on: 'Open',
|
||||||
switchValue: garageList[index].firstSwitch,
|
switchValue: garageDoor.firstSwitch,
|
||||||
action: () {
|
action: () => BlocProvider.of<GarageDoorBloc>(context).add(
|
||||||
BlocProvider.of<GarageDoorBloc>(context).add(
|
|
||||||
ChangeFirstWizardSwitchStatusEvent(
|
ChangeFirstWizardSwitchStatusEvent(
|
||||||
value: garageList[index].firstSwitch,
|
value: garageDoor.firstSwitch,
|
||||||
deviceId: garageList[index].deviceId));
|
deviceId: garageDoor.deviceId,
|
||||||
},
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@ -20,7 +20,8 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => OneGangBloc(switchCode: 'switch_1', oneGangId: device?.uuid ?? '')
|
create: (context) =>
|
||||||
|
OneGangBloc(switchCode: 'switch_1', oneGangId: device?.uuid ?? '')
|
||||||
..add(const InitialEvent(groupScreen: false)),
|
..add(const InitialEvent(groupScreen: false)),
|
||||||
child: BlocBuilder<OneGangBloc, OneGangState>(
|
child: BlocBuilder<OneGangBloc, OneGangState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
@ -36,13 +37,15 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
return state is LoadingInitialState
|
return state is LoadingInitialState
|
||||||
? const Center(
|
? const Center(
|
||||||
child:
|
child: DefaultContainer(
|
||||||
DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
|
width: 50,
|
||||||
|
height: 50,
|
||||||
|
child: CircularProgressIndicator()),
|
||||||
)
|
)
|
||||||
: RefreshIndicator(
|
: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
BlocProvider.of<OneGangBloc>(context)
|
BlocProvider.of<OneGangBloc>(context).add(InitialEvent(
|
||||||
.add(InitialEvent(groupScreen: device != null ? false : true));
|
groupScreen: device != null ? false : true));
|
||||||
},
|
},
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
@ -55,7 +58,8 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
const Expanded(child: SizedBox.shrink()),
|
const Expanded(child: SizedBox.shrink()),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceAround,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
@ -64,9 +68,10 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
threeGangSwitch: device!,
|
threeGangSwitch: device!,
|
||||||
value: oneGangModel.firstSwitch,
|
value: oneGangModel.firstSwitch,
|
||||||
action: () {
|
action: () {
|
||||||
BlocProvider.of<OneGangBloc>(context).add(
|
BlocProvider.of<OneGangBloc>(context)
|
||||||
ChangeFirstSwitchStatusEvent(
|
.add(ChangeFirstSwitchStatusEvent(
|
||||||
value: oneGangModel.firstSwitch));
|
value: oneGangModel
|
||||||
|
.firstSwitch));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
@ -74,7 +79,8 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
width: 70,
|
width: 70,
|
||||||
child: BodySmall(
|
child: BodySmall(
|
||||||
text: " Entrance Light",
|
text: " Entrance Light",
|
||||||
fontColor: ColorsManager.textPrimaryColor,
|
fontColor:
|
||||||
|
ColorsManager.textPrimaryColor,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -94,19 +100,23 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
Card(
|
Card(
|
||||||
elevation: 3,
|
elevation: 3,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(100),
|
borderRadius:
|
||||||
|
BorderRadius.circular(100),
|
||||||
),
|
),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
PageRouteBuilder(
|
PageRouteBuilder(
|
||||||
pageBuilder:
|
pageBuilder: (context,
|
||||||
(context, animation1, animation2) =>
|
animation1,
|
||||||
|
animation2) =>
|
||||||
TimerScheduleScreen(
|
TimerScheduleScreen(
|
||||||
switchCode: 'switch_1',
|
switchCode:
|
||||||
|
'switch_1',
|
||||||
device: device!,
|
device: device!,
|
||||||
deviceCode: 'countdown_1',
|
deviceCode:
|
||||||
|
'countdown_1',
|
||||||
)));
|
)));
|
||||||
},
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
@ -117,7 +127,9 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
height: 60,
|
height: 60,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey[300],
|
color: Colors.grey[300],
|
||||||
borderRadius: BorderRadius.circular(100),
|
borderRadius:
|
||||||
|
BorderRadius.circular(
|
||||||
|
100),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
@ -125,12 +137,15 @@ class OneGangScreen extends StatelessWidget {
|
|||||||
height: 40,
|
height: 40,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(100),
|
borderRadius:
|
||||||
|
BorderRadius.circular(
|
||||||
|
100),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.access_time,
|
Icons.access_time,
|
||||||
color: ColorsManager.primaryColorWithOpacity,
|
color: ColorsManager
|
||||||
|
.primaryColorWithOpacity,
|
||||||
size: 25,
|
size: 25,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -8,7 +8,11 @@ import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart'
|
|||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||||
|
|
||||||
class WHList extends StatelessWidget {
|
class WHList extends StatelessWidget {
|
||||||
const WHList({super.key, required this.whList, required this.allSwitches});
|
const WHList({
|
||||||
|
required this.whList,
|
||||||
|
required this.allSwitches,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final List<GroupWHModel> whList;
|
final List<GroupWHModel> whList;
|
||||||
final bool allSwitches;
|
final bool allSwitches;
|
||||||
@ -22,43 +26,42 @@ class WHList extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
const BodySmall(text: 'All Lights'),
|
const BodySmall(text: 'All Water Heaters'),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
DevicesDefaultSwitch(
|
DevicesDefaultSwitch(
|
||||||
off: 'OFF',
|
off: 'OFF',
|
||||||
on: 'ON',
|
on: 'ON',
|
||||||
switchValue: allSwitches,
|
switchValue: allSwitches,
|
||||||
action: () {
|
action: () => context.read<WaterHeaterBloc>().add(
|
||||||
BlocProvider.of<WaterHeaterBloc>(context)
|
GroupAllOnEvent(),
|
||||||
.add(GroupAllOnEvent());
|
),
|
||||||
},
|
secondAction: () => context.read<WaterHeaterBloc>().add(
|
||||||
secondAction: () {
|
GroupAllOffEvent(),
|
||||||
BlocProvider.of<WaterHeaterBloc>(context)
|
),
|
||||||
.add(GroupAllOffEvent());
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
ListView.builder(
|
ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
padding: const EdgeInsets.all(0),
|
padding: EdgeInsetsDirectional.zero,
|
||||||
itemCount: whList.length,
|
itemCount: whList.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
final waterHeater = whList[index];
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
BodySmall(text: whList[index].deviceName),
|
BodySmall(text: waterHeater.deviceName),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
DevicesDefaultSwitch(
|
DevicesDefaultSwitch(
|
||||||
off: 'OFF',
|
off: 'OFF',
|
||||||
on: 'ON',
|
on: 'ON',
|
||||||
switchValue: whList[index].firstSwitch,
|
switchValue: waterHeater.firstSwitch,
|
||||||
action: () {
|
action: () => context.read<WaterHeaterBloc>().add(
|
||||||
BlocProvider.of<WaterHeaterBloc>(context).add(
|
|
||||||
ChangeFirstWizardSwitchStatusEvent(
|
ChangeFirstWizardSwitchStatusEvent(
|
||||||
value: whList[index].firstSwitch,
|
value: waterHeater.firstSwitch,
|
||||||
deviceId: whList[index].deviceId));
|
deviceId: waterHeater.deviceId,
|
||||||
},
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
|
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
|
||||||
@ -348,15 +350,18 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
try {
|
try {
|
||||||
dynamic response;
|
dynamic response;
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
if (event.createSceneModel != null) {
|
if (event.createSceneModel != null) {
|
||||||
response = event.updateScene
|
response = event.updateScene
|
||||||
? await SceneApi.updateScene(event.createSceneModel!, event.sceneId)
|
? await SceneApi.updateScene(event.createSceneModel!, event.sceneId)
|
||||||
: await SceneApi.createScene(event.createSceneModel!);
|
: await SceneApi.createScene(event.createSceneModel!);
|
||||||
} else if (event.createAutomationModel != null) {
|
} else if (event.createAutomationModel != null) {
|
||||||
response = event.updateScene
|
response = event.updateScene
|
||||||
? await SceneApi.updateAutomation(
|
? await SceneApi.updateAutomation(event.createAutomationModel!,
|
||||||
event.createAutomationModel!, event.sceneId)
|
event.sceneId, project?.uuid ?? '')
|
||||||
: await SceneApi.createAutomation(event.createAutomationModel!);
|
: await SceneApi.createAutomation(
|
||||||
|
event.createAutomationModel!, project?.uuid ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response['success'] == true) {
|
if (response['success'] == true) {
|
||||||
@ -421,6 +426,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
tasksList.clear();
|
tasksList.clear();
|
||||||
tempTasksList.clear();
|
tempTasksList.clear();
|
||||||
selectedValues.clear();
|
selectedValues.clear();
|
||||||
@ -436,7 +443,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
conditionRule = 'or';
|
conditionRule = 'or';
|
||||||
|
|
||||||
final response = event.isAutomation
|
final response = event.isAutomation
|
||||||
? await SceneApi.getAutomationDetails(event.sceneId)
|
? await SceneApi.getAutomationDetails(
|
||||||
|
event.sceneId, project?.uuid ?? '')
|
||||||
: await SceneApi.getSceneDetails(event.sceneId);
|
: await SceneApi.getSceneDetails(event.sceneId);
|
||||||
if (response.id.isNotEmpty) {
|
if (response.id.isNotEmpty) {
|
||||||
if (event.isAutomation) {
|
if (event.isAutomation) {
|
||||||
@ -605,10 +613,14 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
emit(DeleteSceneLoading());
|
emit(DeleteSceneLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
final response =
|
final response =
|
||||||
sceneType.name == CreateSceneEnum.deviceStatusChanges.name
|
sceneType.name == CreateSceneEnum.deviceStatusChanges.name
|
||||||
? await SceneApi.deleteAutomation(
|
? await SceneApi.deleteAutomation(
|
||||||
automationId: event.sceneId, unitUuid: event.unitUuid)
|
automationId: event.sceneId,
|
||||||
|
unitUuid: event.unitUuid,
|
||||||
|
projectId: project?.uuid ?? '')
|
||||||
: await SceneApi.deleteScene(
|
: await SceneApi.deleteScene(
|
||||||
sceneId: event.sceneId,
|
sceneId: event.sceneId,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -46,8 +46,11 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
|||||||
emit(SceneLoading());
|
emit(SceneLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
if (event.unitId.isNotEmpty) {
|
if (event.unitId.isNotEmpty) {
|
||||||
automationList = await SceneApi.getAutomationByUnitId(event.unitId);
|
automationList = await SceneApi.getAutomationByUnitId(
|
||||||
|
event.unitId, event.communityId, project?.uuid ?? '');
|
||||||
emit(SceneLoaded(scenes, automationList));
|
emit(SceneLoaded(scenes, automationList));
|
||||||
} else {
|
} else {
|
||||||
emit(const SceneError(message: 'Unit ID is empty'));
|
emit(const SceneError(message: 'Unit ID is empty'));
|
||||||
@ -96,11 +99,17 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
|||||||
));
|
));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
final success = await SceneApi.updateAutomationStatus(
|
final success = await SceneApi.updateAutomationStatus(
|
||||||
event.automationId, event.automationStatusUpdate);
|
event.automationId,
|
||||||
|
event.automationStatusUpdate,
|
||||||
|
project?.uuid ?? '');
|
||||||
if (success) {
|
if (success) {
|
||||||
automationList = await SceneApi.getAutomationByUnitId(
|
automationList = await SceneApi.getAutomationByUnitId(
|
||||||
event.automationStatusUpdate.spaceUuid);
|
event.automationStatusUpdate.spaceUuid,
|
||||||
|
event.communityId,
|
||||||
|
project?.uuid ?? '');
|
||||||
newLoadingStates[event.automationId] = false;
|
newLoadingStates[event.automationId] = false;
|
||||||
emit(SceneLoaded(
|
emit(SceneLoaded(
|
||||||
currentState.scenes,
|
currentState.scenes,
|
||||||
|
|||||||
@ -22,11 +22,13 @@ class LoadScenes extends SceneEvent {
|
|||||||
|
|
||||||
class LoadAutomation extends SceneEvent {
|
class LoadAutomation extends SceneEvent {
|
||||||
final String unitId;
|
final String unitId;
|
||||||
|
final String communityId;
|
||||||
|
|
||||||
const LoadAutomation(this.unitId);
|
|
||||||
|
const LoadAutomation(this.unitId, this.communityId);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [unitId];
|
List<Object> get props => [unitId, communityId];
|
||||||
}
|
}
|
||||||
|
|
||||||
class SceneTrigger extends SceneEvent {
|
class SceneTrigger extends SceneEvent {
|
||||||
@ -43,8 +45,9 @@ class SceneTrigger extends SceneEvent {
|
|||||||
class UpdateAutomationStatus extends SceneEvent {
|
class UpdateAutomationStatus extends SceneEvent {
|
||||||
final String automationId;
|
final String automationId;
|
||||||
final AutomationStatusUpdate automationStatusUpdate;
|
final AutomationStatusUpdate automationStatusUpdate;
|
||||||
|
final String communityId;
|
||||||
|
|
||||||
const UpdateAutomationStatus({required this.automationStatusUpdate, required this.automationId});
|
const UpdateAutomationStatus({required this.automationStatusUpdate, required this.automationId, required this.communityId});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [automationStatusUpdate];
|
List<Object> get props => [automationStatusUpdate];
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_event.dart';
|
||||||
@ -7,19 +5,31 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_event.dart
|
|||||||
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart';
|
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart';
|
||||||
|
|
||||||
class TabBarBloc extends Bloc<TabBarEvent, TabBarState> {
|
class TabBarBloc extends Bloc<TabBarEvent, TabBarState> {
|
||||||
final DeviceManagerBloc deviceManagerBloc;
|
TabBarBloc(this.deviceManagerBloc) : super(const TabBarInitialState()) {
|
||||||
TabBarBloc(this.deviceManagerBloc) : super(const Initial()) {
|
on<TabBarTabChangedEvent>(_onTabBarTabChangedEvent);
|
||||||
on<TabChanged>(_handleTabChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _handleTabChanged(
|
final DeviceManagerBloc deviceManagerBloc;
|
||||||
TabChanged event, Emitter<TabBarState> emit) {
|
|
||||||
|
void _onTabBarTabChangedEvent(
|
||||||
|
TabBarTabChangedEvent event,
|
||||||
|
Emitter<TabBarState> emit,
|
||||||
|
) {
|
||||||
|
_getDevices(event);
|
||||||
|
|
||||||
|
emit(
|
||||||
|
TabBarTabSelectedState(
|
||||||
|
roomId: event.roomId,
|
||||||
|
selectedTabIndex: event.selectedIndex,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _getDevices(TabBarTabChangedEvent event) {
|
||||||
if (event.roomId == "-1") {
|
if (event.roomId == "-1") {
|
||||||
deviceManagerBloc.add(FetchAllDevices());
|
deviceManagerBloc.add(FetchAllDevices());
|
||||||
} else {
|
} else {
|
||||||
deviceManagerBloc.add(FetchDevicesByRoomId(event.roomId, event.unit));
|
deviceManagerBloc.add(FetchDevicesByRoomId(event.roomId, event.unit));
|
||||||
}
|
}
|
||||||
emit(TabSelected(
|
|
||||||
roomId: event.roomId, selectedTabIndex: event.selectedIndex));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,10 +4,14 @@ abstract class TabBarEvent {
|
|||||||
const TabBarEvent();
|
const TabBarEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
class TabChanged extends TabBarEvent {
|
class TabBarTabChangedEvent extends TabBarEvent {
|
||||||
|
const TabBarTabChangedEvent({
|
||||||
|
required this.selectedIndex,
|
||||||
|
required this.roomId,
|
||||||
|
required this.unit,
|
||||||
|
});
|
||||||
|
|
||||||
final int selectedIndex;
|
final int selectedIndex;
|
||||||
final String roomId;
|
final String roomId;
|
||||||
final SpaceModel unit;
|
final SpaceModel unit;
|
||||||
const TabChanged(
|
|
||||||
{required this.selectedIndex, required this.roomId, required this.unit});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,12 +2,16 @@ abstract class TabBarState {
|
|||||||
const TabBarState();
|
const TabBarState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Initial extends TabBarState {
|
class TabBarInitialState extends TabBarState {
|
||||||
const Initial();
|
const TabBarInitialState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class TabSelected extends TabBarState {
|
class TabBarTabSelectedState extends TabBarState {
|
||||||
|
const TabBarTabSelectedState({
|
||||||
|
required this.roomId,
|
||||||
|
required this.selectedTabIndex,
|
||||||
|
});
|
||||||
|
|
||||||
final int selectedTabIndex;
|
final int selectedTabIndex;
|
||||||
final String roomId;
|
final String roomId;
|
||||||
const TabSelected({required this.roomId, required this.selectedTabIndex});
|
|
||||||
}
|
}
|
||||||
|
|||||||
48
lib/features/scene/helper/scene_bloc_factory.dart
Normal file
48
lib/features/scene/helper/scene_bloc_factory.dart
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
|
|
||||||
|
abstract final class SceneBlocFactory {
|
||||||
|
static SceneBloc create({
|
||||||
|
required bool pageType,
|
||||||
|
required HomeCubit homeCubit,
|
||||||
|
}) {
|
||||||
|
final selectedSpace = homeCubit.selectedSpace;
|
||||||
|
final defaultSpace = SpaceModel(
|
||||||
|
id: '-1',
|
||||||
|
name: '',
|
||||||
|
community: Community(
|
||||||
|
uuid: '-1',
|
||||||
|
name: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final spaceId = selectedSpace?.id ?? defaultSpace.id;
|
||||||
|
final space = selectedSpace ?? defaultSpace;
|
||||||
|
final communityUuid =
|
||||||
|
selectedSpace?.community.uuid ?? defaultSpace.community.uuid;
|
||||||
|
|
||||||
|
final sceneBloc = SceneBloc();
|
||||||
|
|
||||||
|
sceneBloc.add(
|
||||||
|
LoadScenes(
|
||||||
|
spaceId,
|
||||||
|
space,
|
||||||
|
showInDevice: pageType,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!pageType) {
|
||||||
|
sceneBloc.add(
|
||||||
|
LoadAutomation(
|
||||||
|
spaceId,
|
||||||
|
communityUuid,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sceneBloc;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,69 +20,69 @@ class SceneRoomsTabBarDevicesView extends StatefulWidget {
|
|||||||
_SceneRoomsTabBarDevicesViewState();
|
_SceneRoomsTabBarDevicesViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SceneRoomsTabBarDevicesViewState
|
class _SceneRoomsTabBarDevicesViewState extends State<SceneRoomsTabBarDevicesView>
|
||||||
extends State<SceneRoomsTabBarDevicesView>
|
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
late final TabController _tabController;
|
late final TabController _tabController;
|
||||||
List<SubSpaceModel>? rooms = [];
|
|
||||||
late final SpaceModel selectedSpace;
|
late final SpaceModel selectedSpace;
|
||||||
|
var rooms = <SubSpaceModel>[];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
selectedSpace = HomeCubit.getInstance().selectedSpace!;
|
selectedSpace = HomeCubit.getInstance().selectedSpace!;
|
||||||
rooms = List.from(HomeCubit.getInstance().selectedSpace?.subspaces ?? []);
|
|
||||||
if (rooms != null) {
|
rooms = List.from(selectedSpace.subspaces);
|
||||||
if (rooms![0].id != '-1') {
|
final defaultSubSpaceModel = SubSpaceModel(
|
||||||
rooms?.insert(
|
|
||||||
0,
|
|
||||||
SubSpaceModel(
|
|
||||||
name: 'All Devices',
|
name: 'All Devices',
|
||||||
devices: context.read<DevicesCubit>().allDevices,
|
devices: context.read<DevicesCubit>().allDevices,
|
||||||
id: '-1',
|
id: '-1',
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (rooms.isNotEmpty) {
|
||||||
|
final isFirstRoomIdValid = rooms[0].id != '-1';
|
||||||
|
if (isFirstRoomIdValid) {
|
||||||
|
rooms.insert(0, defaultSubSpaceModel);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
rooms = [defaultSubSpaceModel];
|
||||||
}
|
}
|
||||||
|
|
||||||
_tabController =
|
_tabController = TabController(length: rooms.length, vsync: this);
|
||||||
TabController(length: rooms!.length, vsync: this, initialIndex: 0);
|
|
||||||
_tabController.addListener(_handleTabSwitched);
|
_tabController.addListener(_handleTabSwitched);
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleTabSwitched() {
|
|
||||||
if (_tabController.indexIsChanging) {
|
|
||||||
final value = _tabController.index;
|
|
||||||
|
|
||||||
/// select tab
|
|
||||||
context.read<TabBarBloc>().add(TabChanged(
|
|
||||||
selectedIndex: value,
|
|
||||||
roomId: rooms?[value].id ?? '',
|
|
||||||
unit: selectedSpace));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
_tabController.dispose();
|
|
||||||
_tabController.removeListener(() {});
|
_tabController.removeListener(() {});
|
||||||
|
_tabController.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleTabSwitched() {
|
||||||
|
if (_tabController.indexIsChanging) {
|
||||||
|
final index = _tabController.index;
|
||||||
|
|
||||||
|
context.read<TabBarBloc>().add(
|
||||||
|
TabBarTabChangedEvent(
|
||||||
|
selectedIndex: index,
|
||||||
|
roomId: rooms[index].id ?? '',
|
||||||
|
unit: selectedSpace,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
title: StringsManager.createScene,
|
padding: EdgeInsetsDirectional.zero,
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
onPressed: () {
|
onPressed: () => navigateToRoute(context, Routes.sceneTasksRoute),
|
||||||
navigateToRoute(context, Routes.sceneTasksRoute);
|
icon: const Icon(Icons.arrow_back_ios),
|
||||||
},
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.arrow_back_ios,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
title: StringsManager.createScene,
|
||||||
child: SceneDevicesBody(tabController: _tabController, rooms: rooms),
|
child: SceneDevicesBody(tabController: _tabController, rooms: rooms),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,75 +1,45 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
|
||||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/scene_listview.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/scene_listview.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/helper/scene_bloc_factory.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/empty_devices_widget.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_grid_view.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_grid_view.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_header.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_header.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/create_unit.dart';
|
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
class SceneView extends StatelessWidget {
|
class SceneView extends StatelessWidget {
|
||||||
|
const SceneView({
|
||||||
|
this.pageType = false,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final bool pageType;
|
final bool pageType;
|
||||||
const SceneView({super.key, this.pageType = false});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (BuildContext context) {
|
create: (context) => SceneBlocFactory.create(
|
||||||
if (pageType) {
|
pageType: pageType,
|
||||||
return SceneBloc()
|
homeCubit: HomeCubit.getInstance(),
|
||||||
..add(LoadScenes(
|
),
|
||||||
HomeCubit.getInstance().selectedSpace?.id ?? '',
|
|
||||||
HomeCubit.getInstance().selectedSpace ??
|
|
||||||
SpaceModel(
|
|
||||||
id: '-1',
|
|
||||||
name: '',
|
|
||||||
community: Community(
|
|
||||||
uuid: '-1',
|
|
||||||
name: '',
|
|
||||||
)),
|
|
||||||
showInDevice: pageType));
|
|
||||||
} else {
|
|
||||||
return SceneBloc()
|
|
||||||
..add(LoadScenes(
|
|
||||||
HomeCubit.getInstance().selectedSpace?.id ?? '',
|
|
||||||
HomeCubit.getInstance().selectedSpace ??
|
|
||||||
SpaceModel(
|
|
||||||
id: '-1',
|
|
||||||
name: '',
|
|
||||||
community: Community(
|
|
||||||
uuid: '-1',
|
|
||||||
name: '',
|
|
||||||
)),
|
|
||||||
showInDevice: pageType))
|
|
||||||
..add(LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? ''));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
final selectedSpace = HomeCubit.getInstance().selectedSpace;
|
||||||
if (state is DeleteSceneSuccess) {
|
if (state is DeleteSceneSuccess) {
|
||||||
if (state.success) {
|
if (state.success) _loadScenesAndAutomations(context, selectedSpace);
|
||||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
|
||||||
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!,
|
|
||||||
showInDevice: pageType));
|
|
||||||
BlocProvider.of<SceneBloc>(context)
|
|
||||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (state is CreateSceneWithTasks) {
|
if (state is CreateSceneWithTasks) {
|
||||||
if (state.success == true) {
|
if (state.success) {
|
||||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
_loadScenesAndAutomations(context, selectedSpace);
|
||||||
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!,
|
|
||||||
showInDevice: pageType));
|
|
||||||
BlocProvider.of<SceneBloc>(context)
|
|
||||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id));
|
|
||||||
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,23 +47,24 @@ class SceneView extends StatelessWidget {
|
|||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is SceneTriggerSuccess) {
|
if (state is SceneTriggerSuccess) {
|
||||||
context.showCustomSnackbar(
|
context.showCustomSnackbar(
|
||||||
message: 'Scene ${state.sceneName} triggered successfully!');
|
message: 'Scene ${state.sceneName} triggered successfully!',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: HomeCubit.getInstance().spaces?.isEmpty ?? true
|
child: HomeCubit.getInstance().spaces.isEmpty
|
||||||
? const CreateUnitWidget()
|
? const EmptyDevicesWidget()
|
||||||
: Column(
|
: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
if (pageType == false) const SceneHeader(),
|
if (!pageType) ...[
|
||||||
if (pageType == false) const SizedBox(height: 8),
|
const SceneHeader(),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
],
|
||||||
BlocBuilder<SceneBloc, SceneState>(
|
BlocBuilder<SceneBloc, SceneState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is SceneLoading) {
|
if (state is SceneLoading) {
|
||||||
return const Center(
|
return const AppLoadingIndicator();
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (state is SceneError) {
|
if (state is SceneError) {
|
||||||
return Center(
|
return Center(
|
||||||
@ -103,80 +74,83 @@ class SceneView extends StatelessWidget {
|
|||||||
if (state is SceneLoaded) {
|
if (state is SceneLoaded) {
|
||||||
final scenes = state.scenes;
|
final scenes = state.scenes;
|
||||||
final automationList = state.automationList;
|
final automationList = state.automationList;
|
||||||
|
if (scenes.isEmpty) return const EmptyDevicesWidget();
|
||||||
|
|
||||||
return pageType
|
if (pageType) {
|
||||||
? Expanded(
|
return SizedBox(
|
||||||
|
height: context.height * 0.1,
|
||||||
child: SceneListview(
|
child: SceneListview(
|
||||||
scenes: scenes,
|
scenes: scenes,
|
||||||
loadingSceneId: state.loadingSceneId,
|
loadingSceneId: state.loadingSceneId,
|
||||||
))
|
),
|
||||||
: Expanded(
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Theme(
|
||||||
|
data: Theme.of(context).copyWith(
|
||||||
|
dividerColor: Colors.transparent,
|
||||||
|
),
|
||||||
|
child: Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
Theme(
|
ExpansionTile(
|
||||||
data: ThemeData()
|
tilePadding: const EdgeInsets.symmetric(
|
||||||
.copyWith(dividerColor: Colors.transparent),
|
horizontal: 6,
|
||||||
child: ExpansionTile(
|
),
|
||||||
tilePadding: const EdgeInsets.symmetric(horizontal: 6),
|
|
||||||
initiallyExpanded: true,
|
initiallyExpanded: true,
|
||||||
iconColor: ColorsManager.grayColor,
|
iconColor: ColorsManager.grayColor,
|
||||||
title: const BodyMedium(text: 'Tap to run routines'),
|
title: const BodyMedium(
|
||||||
|
text: 'Tap to run routines',
|
||||||
|
),
|
||||||
children: [
|
children: [
|
||||||
scenes.isNotEmpty
|
if (scenes.isNotEmpty)
|
||||||
? SceneGrid(
|
SceneGrid(
|
||||||
scenes: scenes,
|
scenes: scenes,
|
||||||
loadingSceneId: state.loadingSceneId,
|
loadingSceneId: state.loadingSceneId,
|
||||||
disablePlayButton: false,
|
disablePlayButton: false,
|
||||||
loadingStates:
|
loadingStates: state.loadingStates,
|
||||||
state.loadingStates, // Add this line
|
|
||||||
)
|
)
|
||||||
: const Center(
|
else
|
||||||
|
const Center(
|
||||||
child: BodyMedium(
|
child: BodyMedium(
|
||||||
text: 'No scenes have been added yet',
|
text: 'No scenes have been added yet',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(height: 10),
|
||||||
height: 10,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
ExpansionTile(
|
||||||
Theme(
|
|
||||||
data: ThemeData()
|
|
||||||
.copyWith(dividerColor: Colors.transparent),
|
|
||||||
child: ExpansionTile(
|
|
||||||
initiallyExpanded: true,
|
initiallyExpanded: true,
|
||||||
iconColor: ColorsManager.grayColor,
|
iconColor: ColorsManager.grayColor,
|
||||||
tilePadding: const EdgeInsets.symmetric(horizontal: 6),
|
tilePadding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 6,
|
||||||
|
),
|
||||||
title: const BodyMedium(text: 'Automation'),
|
title: const BodyMedium(text: 'Automation'),
|
||||||
children: [
|
children: [
|
||||||
automationList.isNotEmpty
|
if (automationList.isNotEmpty)
|
||||||
? SceneGrid(
|
SceneGrid(
|
||||||
scenes: automationList,
|
scenes: automationList,
|
||||||
loadingSceneId: state.loadingSceneId,
|
loadingSceneId: state.loadingSceneId,
|
||||||
disablePlayButton: true,
|
disablePlayButton: true,
|
||||||
loadingStates:
|
loadingStates: state.loadingStates,
|
||||||
state.loadingStates, // Add this line
|
|
||||||
)
|
)
|
||||||
: const Center(
|
else
|
||||||
|
const Center(
|
||||||
child: BodyMedium(
|
child: BodyMedium(
|
||||||
text: 'No automations have been added yet',
|
text:
|
||||||
|
'No automations have been added yet',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(height: 10),
|
||||||
height: 10,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 15),
|
||||||
const SizedBox(
|
|
||||||
height: 15,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return const SizedBox();
|
return const SizedBox.shrink();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -186,4 +160,21 @@ class SceneView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _loadScenesAndAutomations(BuildContext context, SpaceModel? selectedSpace) {
|
||||||
|
BlocProvider.of<SceneBloc>(context)
|
||||||
|
..add(
|
||||||
|
LoadScenes(
|
||||||
|
selectedSpace!.id,
|
||||||
|
selectedSpace,
|
||||||
|
showInDevice: pageType,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
..add(
|
||||||
|
LoadAutomation(
|
||||||
|
selectedSpace.id,
|
||||||
|
selectedSpace.community.uuid,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class DeleteRoutineButton extends StatelessWidget {
|
|||||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
||||||
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!));
|
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!));
|
||||||
BlocProvider.of<SceneBloc>(context)
|
BlocProvider.of<SceneBloc>(context)
|
||||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id));
|
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id,HomeCubit.getInstance().selectedSpace!.community.uuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
22
lib/features/scene/widgets/empty_devices_widget.dart
Normal file
22
lib/features/scene/widgets/empty_devices_widget.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class EmptyDevicesWidget extends StatelessWidget {
|
||||||
|
const EmptyDevicesWidget({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 48),
|
||||||
|
child: Text(
|
||||||
|
"No routines.\nEnable 'Show on Home Screen' to add routines",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
color: ColorsManager.grayColor,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||||
@ -8,60 +7,44 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_bloc.dart'
|
|||||||
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart';
|
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart';
|
||||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_devices/scene_devices_body_tab_bar.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_devices/scene_devices_list.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.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/context_extension.dart';
|
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|
||||||
|
|
||||||
class SceneDevicesBody extends StatelessWidget {
|
class SceneDevicesBody extends StatelessWidget {
|
||||||
const SceneDevicesBody({
|
const SceneDevicesBody({
|
||||||
super.key,
|
required this.tabController,
|
||||||
required TabController tabController,
|
|
||||||
required this.rooms,
|
required this.rooms,
|
||||||
}) : _tabController = tabController;
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final TabController _tabController;
|
final TabController tabController;
|
||||||
final List<SubSpaceModel>? rooms;
|
final List<SubSpaceModel> rooms;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isAutomationDeviceStatus =
|
|
||||||
((ModalRoute.of(context)?.settings.arguments as SceneSettingsRouteArguments?)?.sceneType ==
|
|
||||||
CreateSceneEnum.deviceStatusChanges.name);
|
|
||||||
return BlocBuilder<TabBarBloc, TabBarState>(
|
return BlocBuilder<TabBarBloc, TabBarState>(
|
||||||
builder: (context, tabState) {
|
builder: (context, state) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
TabBar(
|
SceneDevicesBodyTabBar(
|
||||||
controller: _tabController,
|
tabController: tabController,
|
||||||
dividerColor: Colors.transparent,
|
rooms: rooms,
|
||||||
indicatorColor: Colors.transparent,
|
selectedRoomId: state is TabBarTabSelectedState ? state.roomId : '-1',
|
||||||
tabs: [
|
|
||||||
...rooms!.map((e) => Tab(
|
|
||||||
child: BodyLarge(
|
|
||||||
text: e.name ?? '',
|
|
||||||
textAlign: TextAlign.start,
|
|
||||||
style: context.bodyLarge.copyWith(
|
|
||||||
color: (tabState is TabSelected) && tabState.roomId == e.id
|
|
||||||
? ColorsManager.textPrimaryColor
|
|
||||||
: ColorsManager.textPrimaryColor.withOpacity(0.2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
isScrollable: true,
|
|
||||||
tabAlignment: TabAlignment.start,
|
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TabBarView(
|
child: TabBarView(
|
||||||
controller: _tabController,
|
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
children:
|
controller: tabController,
|
||||||
rooms!.map((e) => _buildRoomTab(e, context, isAutomationDeviceStatus)).toList(),
|
children: rooms
|
||||||
|
.map(
|
||||||
|
(room) => _buildRoomTab(
|
||||||
|
room,
|
||||||
|
_isAutomationDeviceStatus(context),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -70,52 +53,46 @@ class SceneDevicesBody extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildRoomTab(SubSpaceModel room, BuildContext context, bool isAutomationDeviceStatus) {
|
bool _isAutomationDeviceStatus(BuildContext context) {
|
||||||
|
final routeArguments =
|
||||||
|
ModalRoute.of(context)?.settings.arguments as SceneSettingsRouteArguments?;
|
||||||
|
final deviceStatusChangesScene = CreateSceneEnum.deviceStatusChanges.name;
|
||||||
|
final sceneType = routeArguments?.sceneType;
|
||||||
|
|
||||||
|
return sceneType == deviceStatusChangesScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildRoomTab(
|
||||||
|
SubSpaceModel room,
|
||||||
|
bool isAutomationDeviceStatus,
|
||||||
|
) {
|
||||||
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
|
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state.loading && state.devices == null) {
|
final isLoading = state.loading && state.devices == null;
|
||||||
return const Center(child: CircularProgressIndicator());
|
final hasData =
|
||||||
} else if (state.devices != null && state.devices!.isNotEmpty) {
|
state.devices != null && (state.devices?.isNotEmpty ?? false);
|
||||||
return ListView.builder(
|
final hasError = state.error != null;
|
||||||
itemCount: state.devices!.length,
|
|
||||||
itemBuilder: (context, index) {
|
final widgets = <bool, Widget>{
|
||||||
final device = state.devices![index];
|
isLoading: const AppLoadingIndicator(),
|
||||||
return DefaultContainer(
|
hasError: Center(child: Text('${state.error}')),
|
||||||
child: SceneListTile(
|
hasData: SceneDevicesList(
|
||||||
minLeadingWidth: 40,
|
devices: state.devices ?? [],
|
||||||
leadingWidget: SvgPicture.asset(device.icon ?? ''),
|
isAutomationDeviceStatus: isAutomationDeviceStatus,
|
||||||
titleWidget: BodyMedium(
|
|
||||||
text: device.name ?? '',
|
|
||||||
style: context.titleSmall.copyWith(
|
|
||||||
color: ColorsManager.secondaryTextColor,
|
|
||||||
fontWeight: FontWeight.w400,
|
|
||||||
fontSize: 20,
|
|
||||||
),
|
),
|
||||||
),
|
};
|
||||||
trailingWidget: const Icon(
|
|
||||||
Icons.arrow_forward_ios_rounded,
|
final invalidWidgetEntry = MapEntry(
|
||||||
color: ColorsManager.greyColor,
|
true,
|
||||||
size: 16,
|
Center(child: Text('This subspace has no devices')),
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pushNamed(
|
|
||||||
context,
|
|
||||||
Routes.deviceFunctionsRoute,
|
|
||||||
arguments: {
|
|
||||||
"device": device,
|
|
||||||
"isAutomationDeviceStatus": isAutomationDeviceStatus
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
|
||||||
),
|
final validWidgetEntry = widgets.entries.firstWhere(
|
||||||
|
(entry) => entry.key == true,
|
||||||
|
orElse: () => invalidWidgetEntry,
|
||||||
);
|
);
|
||||||
},
|
|
||||||
);
|
return validWidgetEntry.value;
|
||||||
} else if (state.error != null) {
|
|
||||||
return const Center(child: Text('Something went wrong'));
|
|
||||||
} else {
|
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,46 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class SceneDevicesBodyTabBar extends StatelessWidget {
|
||||||
|
const SceneDevicesBodyTabBar({
|
||||||
|
required this.tabController,
|
||||||
|
required this.rooms,
|
||||||
|
required this.selectedRoomId,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String selectedRoomId;
|
||||||
|
|
||||||
|
final TabController tabController;
|
||||||
|
final List<SubSpaceModel> rooms;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return TabBar(
|
||||||
|
controller: tabController,
|
||||||
|
dividerColor: Colors.transparent,
|
||||||
|
indicatorColor: Colors.transparent,
|
||||||
|
isScrollable: true,
|
||||||
|
tabAlignment: TabAlignment.start,
|
||||||
|
tabs: rooms.map((e) {
|
||||||
|
final isSelected = selectedRoomId == e.id;
|
||||||
|
return Tab(
|
||||||
|
child: BodyLarge(
|
||||||
|
text: e.name ?? '',
|
||||||
|
textAlign: TextAlign.start,
|
||||||
|
style: context.bodyLarge.copyWith(
|
||||||
|
color: isSelected
|
||||||
|
? ColorsManager.textPrimaryColor
|
||||||
|
: ColorsManager.textPrimaryColor.withValues(
|
||||||
|
alpha: 0.2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/default_container.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/context_extension.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class SceneDevicesList extends StatelessWidget {
|
||||||
|
const SceneDevicesList({
|
||||||
|
required this.isAutomationDeviceStatus,
|
||||||
|
required this.devices,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
final List<DeviceModel> devices;
|
||||||
|
final bool isAutomationDeviceStatus;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: devices.length,
|
||||||
|
itemBuilder: (context, index) => _buildDeviceTile(context, devices[index]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildDeviceTile(
|
||||||
|
BuildContext context,
|
||||||
|
DeviceModel device,
|
||||||
|
) {
|
||||||
|
return DefaultContainer(
|
||||||
|
child: SceneListTile(
|
||||||
|
minLeadingWidth: 40,
|
||||||
|
leadingWidget: SvgPicture.asset(device.icon ?? ''),
|
||||||
|
titleWidget: BodyMedium(
|
||||||
|
text: device.name ?? '',
|
||||||
|
style: context.titleSmall.copyWith(
|
||||||
|
color: ColorsManager.secondaryTextColor,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
trailingWidget: const Icon(
|
||||||
|
Icons.arrow_forward_ios_rounded,
|
||||||
|
color: ColorsManager.greyColor,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
|
onPressed: () => _navigateToDeviceFunctions(context, device),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _navigateToDeviceFunctions(
|
||||||
|
BuildContext context,
|
||||||
|
DeviceModel device,
|
||||||
|
) {
|
||||||
|
Navigator.of(context).pushNamed(
|
||||||
|
Routes.deviceFunctionsRoute,
|
||||||
|
arguments: {
|
||||||
|
"device": device,
|
||||||
|
"isAutomationDeviceStatus": isAutomationDeviceStatus,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -132,6 +132,10 @@ class SceneItem extends StatelessWidget {
|
|||||||
spaceUuid: HomeCubit.getInstance()
|
spaceUuid: HomeCubit.getInstance()
|
||||||
.selectedSpace!
|
.selectedSpace!
|
||||||
.id),
|
.id),
|
||||||
|
communityId: HomeCubit.getInstance()
|
||||||
|
.selectedSpace!
|
||||||
|
.community
|
||||||
|
.uuid,
|
||||||
automationId: scene.id));
|
automationId: scene.id));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class SmartEnableAutomation extends StatelessWidget {
|
|||||||
child: BlocBuilder<SceneBloc, SceneState>(
|
child: BlocBuilder<SceneBloc, SceneState>(
|
||||||
bloc: context.read<SceneBloc>()
|
bloc: context.read<SceneBloc>()
|
||||||
..add(
|
..add(
|
||||||
LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '')),
|
LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '',HomeCubit.getInstance().selectedSpace?.community.uuid ?? '')),
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is SceneLoading) {
|
if (state is SceneLoading) {
|
||||||
return const Align(
|
return const Align(
|
||||||
|
|||||||
12
lib/features/shared_widgets/app_loading_indicator.dart
Normal file
12
lib/features/shared_widgets/app_loading_indicator.dart
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class AppLoadingIndicator extends StatelessWidget {
|
||||||
|
const AppLoadingIndicator({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: CircularProgressIndicator.adaptive(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,8 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/view/app_layout.dart';
|
import 'package:syncrow_app/features/app_layout/view/app_layout.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/otp_view.dart';
|
|
||||||
import 'package:syncrow_app/features/auth/view/login_view.dart';
|
import 'package:syncrow_app/features/auth/view/login_view.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/view/otp_view.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/sign_up_view.dart';
|
import 'package:syncrow_app/features/auth/view/sign_up_view.dart';
|
||||||
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
|
||||||
@ -17,11 +17,12 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_bloc.dart'
|
|||||||
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_event.dart';
|
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_event.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/device_functions_view.dart';
|
import 'package:syncrow_app/features/scene/view/device_functions_view.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_auto_settings.dart';
|
import 'package:syncrow_app/features/scene/view/scene_auto_settings.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart';
|
|
||||||
import 'package:syncrow_app/features/scene/view/scene_rooms_tabbar.dart';
|
import 'package:syncrow_app/features/scene/view/scene_rooms_tabbar.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||||
import 'package:syncrow_app/features/scene/view/smart_automation_select_route.dart';
|
import 'package:syncrow_app/features/scene/view/smart_automation_select_route.dart';
|
||||||
import 'package:syncrow_app/features/splash/view/splash_view.dart';
|
import 'package:syncrow_app/features/splash/view/splash_view.dart';
|
||||||
|
|
||||||
import 'routing_constants.dart';
|
import 'routing_constants.dart';
|
||||||
|
|
||||||
class Router {
|
class Router {
|
||||||
@ -88,7 +89,7 @@ class Router {
|
|||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (BuildContext context) =>
|
create: (BuildContext context) =>
|
||||||
TabBarBloc(context.read<DeviceManagerBloc>())
|
TabBarBloc(context.read<DeviceManagerBloc>())
|
||||||
..add(TabChanged(
|
..add(TabBarTabChangedEvent(
|
||||||
selectedIndex: 0,
|
selectedIndex: 0,
|
||||||
roomId: '-1',
|
roomId: '-1',
|
||||||
unit: SpaceModel(
|
unit: SpaceModel(
|
||||||
|
|||||||
@ -11,7 +11,7 @@ abstract class ApiEndpoints {
|
|||||||
static const String sendOtp = '/authentication/user/send-otp';
|
static const String sendOtp = '/authentication/user/send-otp';
|
||||||
static const String verifyOtp = '/authentication/user/verify-otp';
|
static const String verifyOtp = '/authentication/user/verify-otp';
|
||||||
static const String forgetPassword = '/authentication/user/forget-password';
|
static const String forgetPassword = '/authentication/user/forget-password';
|
||||||
|
static const String clientLogin = 'client/token';
|
||||||
////////////////////////////////////// Spaces ///////////////////////////////////////
|
////////////////////////////////////// Spaces ///////////////////////////////////////
|
||||||
|
|
||||||
///Community Module
|
///Community Module
|
||||||
@ -111,9 +111,9 @@ abstract class ApiEndpoints {
|
|||||||
//POST
|
//POST
|
||||||
static const String addDeviceToRoom = '/device/room';
|
static const String addDeviceToRoom = '/device/room';
|
||||||
static const String addDeviceToGroup = '/device/group';
|
static const String addDeviceToGroup = '/device/group';
|
||||||
static const String controlDevice = '/device/{deviceUuid}/control';
|
static const String controlDevice = '/devices/{deviceUuid}/command';
|
||||||
static const String firmwareDevice =
|
static const String firmwareDevice =
|
||||||
'/device/{deviceUuid}/firmware/{firmwareVersion}';
|
'/devices/{deviceUuid}/firmware/{firmwareVersion}';
|
||||||
static const String getDevicesByUserId = '/device/user/{userId}';
|
static const String getDevicesByUserId = '/device/user/{userId}';
|
||||||
static const String getDevicesByUnitId = '/device/unit/{unitUuid}';
|
static const String getDevicesByUnitId = '/device/unit/{unitUuid}';
|
||||||
static const String openDoorLock = '/door-lock/open/{doorLockUuid}';
|
static const String openDoorLock = '/door-lock/open/{doorLockUuid}';
|
||||||
@ -121,13 +121,13 @@ abstract class ApiEndpoints {
|
|||||||
//GET
|
//GET
|
||||||
static const String deviceByRoom =
|
static const String deviceByRoom =
|
||||||
'/projects/{projectUuid}/communities/{communityUuid}/spaces/{spaceUuid}/subspaces/{subSpaceUuid}/devices';
|
'/projects/{projectUuid}/communities/{communityUuid}/spaces/{spaceUuid}/subspaces/{subSpaceUuid}/devices';
|
||||||
static const String deviceByUuid = '/device/{deviceUuid}';
|
static const String deviceByUuid = '/devices/{deviceUuid}';
|
||||||
static const String deviceFunctions = '/device/{deviceUuid}/functions';
|
static const String deviceFunctions = '/devices/{deviceUuid}/functions';
|
||||||
static const String gatewayApi = '/device/gateway/{gatewayUuid}/devices';
|
static const String gatewayApi = '/devices/gateway/{gatewayUuid}/devices';
|
||||||
static const String deviceFunctionsStatus =
|
static const String deviceFunctionsStatus =
|
||||||
'/device/{deviceUuid}/functions/status';
|
'/devices/{deviceUuid}/functions/status';
|
||||||
static const String powerClamp =
|
static const String powerClamp =
|
||||||
'/device/{powerClampUuid}/power-clamp/status';
|
'/devices/{deviceUuid}/functions/status';
|
||||||
|
|
||||||
///Device Permission Module
|
///Device Permission Module
|
||||||
//POST
|
//POST
|
||||||
@ -144,7 +144,7 @@ abstract class ApiEndpoints {
|
|||||||
/// POST
|
/// POST
|
||||||
static const String createScene = '/scene/tap-to-run';
|
static const String createScene = '/scene/tap-to-run';
|
||||||
static const String triggerScene = '/scene/tap-to-run/{sceneId}/trigger';
|
static const String triggerScene = '/scene/tap-to-run/{sceneId}/trigger';
|
||||||
static const String createAutomation = '/automation';
|
static const String createAutomation = '/projects/{projectId}/automations';
|
||||||
|
|
||||||
/// GET
|
/// GET
|
||||||
static const String getUnitScenes =
|
static const String getUnitScenes =
|
||||||
@ -153,23 +153,26 @@ abstract class ApiEndpoints {
|
|||||||
static const String getScene = '/scene/tap-to-run/{sceneId}';
|
static const String getScene = '/scene/tap-to-run/{sceneId}';
|
||||||
static const String getIconScene = '/scene/icon';
|
static const String getIconScene = '/scene/icon';
|
||||||
|
|
||||||
static const String getUnitAutomation = '/automation/{unitUuid}';
|
static const String getUnitAutomation =
|
||||||
|
'/projects/{projectId}/communities/{communityId}/spaces/{unitUuid}/automations';
|
||||||
|
|
||||||
static const String getAutomationDetails =
|
static const String getAutomationDetails =
|
||||||
'/automation/details/{automationId}';
|
'/projects/{projectId}/automations/{automationId}';
|
||||||
|
|
||||||
/// PUT
|
/// PUT
|
||||||
static const String updateScene = '/scene/tap-to-run/{sceneId}';
|
static const String updateScene = '/scene/tap-to-run/{sceneId}';
|
||||||
|
|
||||||
static const String updateAutomation = '/automation/{automationId}';
|
static const String updateAutomation =
|
||||||
|
'/projects/{projectId}/automations/{automationId}';
|
||||||
|
|
||||||
static const String updateAutomationStatus =
|
static const String updateAutomationStatus =
|
||||||
'/automation/status/{automationId}';
|
'/projects/{projectId}/automations/{automationId}';
|
||||||
|
|
||||||
/// DELETE
|
/// DELETE
|
||||||
static const String deleteScene = '/scene/tap-to-run/{sceneId}';
|
static const String deleteScene = '/scene/tap-to-run/{sceneId}';
|
||||||
|
|
||||||
static const String deleteAutomation = '/automation/{automationId}';
|
static const String deleteAutomation =
|
||||||
|
'/projects/{projectId}/automations/{automationId}';
|
||||||
|
|
||||||
//////////////////////Door Lock //////////////////////
|
//////////////////////Door Lock //////////////////////
|
||||||
//online
|
//online
|
||||||
@ -213,18 +216,18 @@ abstract class ApiEndpoints {
|
|||||||
static const String changeSchedule = '/schedule/enable/{deviceUuid}';
|
static const String changeSchedule = '/schedule/enable/{deviceUuid}';
|
||||||
static const String deleteSchedule = '/schedule/{deviceUuid}/{scheduleId}';
|
static const String deleteSchedule = '/schedule/{deviceUuid}/{scheduleId}';
|
||||||
static const String reportLogs =
|
static const String reportLogs =
|
||||||
'/device/report-logs/{deviceUuid}?code={code}&startTime={startTime}&endTime={endTime}';
|
'/devices/report-logs/{deviceUuid}?code={code}&startTime={startTime}&endTime={endTime}';
|
||||||
static const String controlBatch = '/device/control/batch';
|
static const String controlBatch = '/devices/batch';
|
||||||
static const String statusBatch = '/device/status/batch';
|
static const String statusBatch = '/devices/batch';
|
||||||
static const String deviceScene = '/device/{deviceUuid}/scenes';
|
static const String deviceScene = '/devices/{deviceUuid}/scenes';
|
||||||
|
|
||||||
static const String fourSceneByName =
|
static const String fourSceneByName =
|
||||||
'/device/{deviceUuid}/scenes?switchName={switchName}';
|
'/devices/{deviceUuid}/scenes?switchName={switchName}';
|
||||||
|
|
||||||
static const String resetDevice = '/factory/reset/{deviceUuid}';
|
static const String resetDevice = '/factory/reset/{deviceUuid}';
|
||||||
static const String unAssignScenesDevice =
|
static const String unAssignScenesDevice =
|
||||||
'/device/{deviceUuid}/scenes?switchName={switchName}';
|
'/devices/{deviceUuid}/scenes?switchName={switchName}';
|
||||||
static const String getDeviceLogs = '/device/report-logs/{uuid}?code={code}';
|
static const String getDeviceLogs = '/devices/report-logs/{uuid}?code={code}';
|
||||||
static const String terms = '/terms';
|
static const String terms = '/terms';
|
||||||
static const String policy = '/policy';
|
static const String policy = '/policy';
|
||||||
static const String getPermission = '/permission/{roleUuid}';
|
static const String getPermission = '/permission/{roleUuid}';
|
||||||
|
|||||||
@ -25,11 +25,15 @@ class AuthenticationAPI {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> signUp({required SignUpModel model}) async {
|
static Future<bool> signUp({
|
||||||
|
required SignUpModel model,
|
||||||
|
required String accessToken,
|
||||||
|
}) async {
|
||||||
final response = await HTTPService().post(
|
final response = await HTTPService().post(
|
||||||
path: ApiEndpoints.signUp,
|
path: ApiEndpoints.signUp,
|
||||||
body: model.toJson(),
|
body: model.toJson(),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
|
accessToken: accessToken,
|
||||||
expectedResponseModel: (json) => json['statusCode'] == 201);
|
expectedResponseModel: (json) => json['statusCode'] == 201);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@ -63,4 +67,20 @@ class AuthenticationAPI {
|
|||||||
expectedResponseModel: (json) => json['data']);
|
expectedResponseModel: (json) => json['data']);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<Map<String, dynamic>> fetchClientToken({
|
||||||
|
required String clientId,
|
||||||
|
required String clientSecret,
|
||||||
|
}) async {
|
||||||
|
final response = await HTTPService().post(
|
||||||
|
path: ApiEndpoints.clientLogin,
|
||||||
|
body: {
|
||||||
|
'clientId': clientId,
|
||||||
|
'clientSecret': clientSecret,
|
||||||
|
},
|
||||||
|
showServerMessage: false,
|
||||||
|
expectedResponseModel: (json) => json['data'],
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
|
||||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.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';
|
||||||
@ -8,7 +7,6 @@ import 'package:syncrow_app/features/devices/model/device_report_model.dart';
|
|||||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||||
import 'package:syncrow_app/services/api/http_service.dart';
|
import 'package:syncrow_app/services/api/http_service.dart';
|
||||||
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
|
||||||
import '../../features/devices/model/create_temporary_password_model.dart';
|
import '../../features/devices/model/create_temporary_password_model.dart';
|
||||||
|
|
||||||
class DevicesAPI {
|
class DevicesAPI {
|
||||||
@ -39,7 +37,7 @@ class DevicesAPI {
|
|||||||
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
|
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
|
||||||
body: {"deviceName": deviceName},
|
body: {"deviceName": deviceName},
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json['data'];
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
@ -92,7 +90,7 @@ class DevicesAPI {
|
|||||||
.replaceAll('{deviceUuid}', deviceId),
|
.replaceAll('{deviceUuid}', deviceId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json['data'];
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
@ -101,7 +99,7 @@ class DevicesAPI {
|
|||||||
static Future<Map<String, dynamic>> getPowerClampStatus(
|
static Future<Map<String, dynamic>> getPowerClampStatus(
|
||||||
String deviceId) async {
|
String deviceId) async {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.powerClamp.replaceAll('{powerClampUuid}', deviceId),
|
path: ApiEndpoints.deviceFunctionsStatus.replaceAll('{powerClampUuid}', deviceId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json;
|
||||||
@ -132,7 +130,7 @@ class DevicesAPI {
|
|||||||
path: ApiEndpoints.deviceFunctions.replaceAll('{deviceUuid}', deviceId),
|
path: ApiEndpoints.deviceFunctions.replaceAll('{deviceUuid}', deviceId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
final functions = FunctionModel.fromJson(json);
|
final functions = FunctionModel.fromJson(json['data']);
|
||||||
return functions;
|
return functions;
|
||||||
});
|
});
|
||||||
return response;
|
return response;
|
||||||
@ -188,7 +186,7 @@ class DevicesAPI {
|
|||||||
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
|
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json['data'];
|
||||||
});
|
});
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@ -264,7 +262,7 @@ class DevicesAPI {
|
|||||||
if (json == null || json.isEmpty || json == []) {
|
if (json == null || json.isEmpty || json == []) {
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
for (var device in json['devices']) {
|
for (var device in json['data']['devices']) {
|
||||||
devices.add(DeviceModel.fromJson(device));
|
devices.add(DeviceModel.fromJson(device));
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
@ -491,7 +489,12 @@ class DevicesAPI {
|
|||||||
}) async {
|
}) async {
|
||||||
final response = await _httpService.post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.controlBatch,
|
path: ApiEndpoints.controlBatch,
|
||||||
body: {"devicesUuid": devicesUuid, "code": code, "value": value},
|
body: {
|
||||||
|
"devicesUuid": devicesUuid,
|
||||||
|
"code": code,
|
||||||
|
"value": value,
|
||||||
|
"operationType": 'COMMAND',
|
||||||
|
},
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json;
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class HomeManagementAPI {
|
|||||||
path: ApiEndpoints.devices.replaceAll("{projectUuid}", projectUuid),
|
path: ApiEndpoints.devices.replaceAll("{projectUuid}", projectUuid),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
json.forEach((value) {
|
json['data'].forEach((value) {
|
||||||
list.add(DeviceModel.fromJson(value));
|
list.add(DeviceModel.fromJson(value));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -48,13 +48,26 @@ class HTTPService {
|
|||||||
Options? options,
|
Options? options,
|
||||||
dynamic body,
|
dynamic body,
|
||||||
bool showServerMessage = true,
|
bool showServerMessage = true,
|
||||||
|
String? accessToken,
|
||||||
required T Function(dynamic) expectedResponseModel}) async {
|
required T Function(dynamic) expectedResponseModel}) async {
|
||||||
try {
|
try {
|
||||||
|
final authOptions = options ??
|
||||||
|
Options(
|
||||||
|
headers: accessToken != null
|
||||||
|
? {
|
||||||
|
'Authorization': 'Bearer $accessToken',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
final response = await client.post(
|
final response = await client.post(
|
||||||
path,
|
path,
|
||||||
data: body,
|
data: body,
|
||||||
queryParameters: queryParameters,
|
queryParameters: queryParameters,
|
||||||
options: options,
|
options: authOptions,
|
||||||
);
|
);
|
||||||
return expectedResponseModel(response.data);
|
return expectedResponseModel(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
|||||||
import 'package:syncrow_app/features/scene/model/update_automation.dart';
|
import 'package:syncrow_app/features/scene/model/update_automation.dart';
|
||||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||||
import 'package:syncrow_app/services/api/http_service.dart';
|
import 'package:syncrow_app/services/api/http_service.dart';
|
||||||
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
|
||||||
|
|
||||||
class SceneApi {
|
class SceneApi {
|
||||||
static final HTTPService _httpService = HTTPService();
|
static final HTTPService _httpService = HTTPService();
|
||||||
@ -31,10 +30,11 @@ class SceneApi {
|
|||||||
|
|
||||||
// create automation
|
// create automation
|
||||||
static Future<Map<String, dynamic>> createAutomation(
|
static Future<Map<String, dynamic>> createAutomation(
|
||||||
CreateAutomationModel createAutomationModel) async {
|
CreateAutomationModel createAutomationModel, String projectId) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.createAutomation,
|
path:
|
||||||
|
ApiEndpoints.createAutomation.replaceAll('{projectId}', projectId),
|
||||||
body: createAutomationModel.toMap(),
|
body: createAutomationModel.toMap(),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
@ -78,10 +78,17 @@ class SceneApi {
|
|||||||
|
|
||||||
//getAutomation
|
//getAutomation
|
||||||
|
|
||||||
static Future<List<ScenesModel>> getAutomationByUnitId(String unitId) async {
|
static Future<List<ScenesModel>> getAutomationByUnitId(
|
||||||
|
String unitId,
|
||||||
|
String communityId,
|
||||||
|
String projectId,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.getUnitAutomation.replaceAll('{unitUuid}', unitId),
|
path: ApiEndpoints.getUnitAutomation
|
||||||
|
.replaceAll('{unitUuid}', unitId)
|
||||||
|
.replaceAll('{communityId}', communityId)
|
||||||
|
.replaceAll('{projectId}', projectId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
List<ScenesModel> scenes = [];
|
List<ScenesModel> scenes = [];
|
||||||
@ -112,11 +119,12 @@ class SceneApi {
|
|||||||
|
|
||||||
//automation details
|
//automation details
|
||||||
static Future<SceneDetailsModel> getAutomationDetails(
|
static Future<SceneDetailsModel> getAutomationDetails(
|
||||||
String automationId) async {
|
String automationId, String projectId) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.getAutomationDetails
|
path: ApiEndpoints.getAutomationDetails
|
||||||
.replaceAll('{automationId}', automationId),
|
.replaceAll('{automationId}', automationId)
|
||||||
|
.replaceAll('{projectId}', projectId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
|
expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
|
||||||
);
|
);
|
||||||
@ -128,11 +136,12 @@ class SceneApi {
|
|||||||
|
|
||||||
//updateAutomationStatus
|
//updateAutomationStatus
|
||||||
static Future<bool> updateAutomationStatus(String automationId,
|
static Future<bool> updateAutomationStatus(String automationId,
|
||||||
AutomationStatusUpdate createAutomationEnable) async {
|
AutomationStatusUpdate createAutomationEnable, String projectId) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.put(
|
final response = await _httpService.patch(
|
||||||
path: ApiEndpoints.updateAutomationStatus
|
path: ApiEndpoints.updateAutomationStatus
|
||||||
.replaceAll('{automationId}', automationId),
|
.replaceAll('{automationId}', automationId)
|
||||||
|
.replaceAll('{projectId}', projectId),
|
||||||
body: createAutomationEnable.toMap(),
|
body: createAutomationEnable.toMap(),
|
||||||
expectedResponseModel: (json) => json['success'],
|
expectedResponseModel: (json) => json['success'],
|
||||||
);
|
);
|
||||||
@ -194,12 +203,13 @@ class SceneApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//update automation
|
//update automation
|
||||||
static updateAutomation(
|
static updateAutomation(CreateAutomationModel createAutomationModel,
|
||||||
CreateAutomationModel createAutomationModel, String automationId) async {
|
String automationId, String projectId) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.put(
|
final response = await _httpService.put(
|
||||||
path: ApiEndpoints.updateAutomation
|
path: ApiEndpoints.updateAutomation
|
||||||
.replaceAll('{automationId}', automationId),
|
.replaceAll('{automationId}', automationId)
|
||||||
|
.replaceAll('{projectId}', projectId),
|
||||||
body: createAutomationModel
|
body: createAutomationModel
|
||||||
.toJson(automationId.isNotEmpty == true ? automationId : null),
|
.toJson(automationId.isNotEmpty == true ? automationId : null),
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
@ -229,11 +239,14 @@ class SceneApi {
|
|||||||
|
|
||||||
// delete automation
|
// delete automation
|
||||||
static Future<bool> deleteAutomation(
|
static Future<bool> deleteAutomation(
|
||||||
{required String unitUuid, required String automationId}) async {
|
{required String unitUuid,
|
||||||
|
required String automationId,
|
||||||
|
required String projectId}) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.delete(
|
final response = await _httpService.delete(
|
||||||
path: ApiEndpoints.deleteAutomation
|
path: ApiEndpoints.deleteAutomation
|
||||||
.replaceAll('{automationId}', automationId),
|
.replaceAll('{automationId}', automationId)
|
||||||
|
.replaceAll('{projectId}', projectId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) => json['statusCode'] == 200,
|
expectedResponseModel: (json) => json['statusCode'] == 200,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user