mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-14 09:17:23 +00:00
fixed space
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import UIKit
|
||||
import Flutter
|
||||
|
||||
@UIApplicationMain
|
||||
@main
|
||||
@objc class AppDelegate: FlutterAppDelegate {
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
|
@ -11,7 +11,7 @@ import 'package:syncrow_app/features/app_layout/view/widgets/app_bar_home_dropdo
|
||||
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
||||
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart';
|
||||
import 'package:syncrow_app/features/menu/view/menu_view.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
@ -55,7 +55,8 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
Future fetchUserInfo() async {
|
||||
try {
|
||||
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||
var uuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||
user = await ProfileApi().fetchUserInfo(uuid);
|
||||
emit(HomeUserInfoLoaded(user!)); // Emit state after fetching user info
|
||||
} catch (e) {
|
||||
@ -76,9 +77,12 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
selectedSpace = null;
|
||||
selectedRoom = null;
|
||||
pageIndex = 0;
|
||||
OneSignal.User.pushSubscription.removeObserver((stateChanges) => oneSignalSubscriptionObserver);
|
||||
OneSignal.Notifications.removePermissionObserver((permission) => oneSignalPermissionObserver);
|
||||
OneSignal.Notifications.removeClickListener((event) => oneSignalClickListenerObserver);
|
||||
OneSignal.User.pushSubscription
|
||||
.removeObserver((stateChanges) => oneSignalSubscriptionObserver);
|
||||
OneSignal.Notifications.removePermissionObserver(
|
||||
(permission) => oneSignalPermissionObserver);
|
||||
OneSignal.Notifications.removeClickListener(
|
||||
(event) => oneSignalClickListenerObserver);
|
||||
return super.close();
|
||||
}
|
||||
|
||||
@ -88,7 +92,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
SpaceModel? selectedSpace;
|
||||
|
||||
RoomModel? selectedRoom;
|
||||
SubSpaceModel? selectedRoom;
|
||||
|
||||
PageController devicesPageController = PageController();
|
||||
|
||||
@ -120,7 +124,9 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
return;
|
||||
}
|
||||
|
||||
var userUuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? '';
|
||||
var userUuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ??
|
||||
'';
|
||||
if (userUuid.isNotEmpty) {
|
||||
await OneSignal.login(userUuid);
|
||||
}
|
||||
@ -128,21 +134,24 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
await OneSignal.User.pushSubscription.optIn();
|
||||
|
||||
//this function will be called once a user is subscribed
|
||||
oneSignalSubscriptionObserver = OneSignal.User.pushSubscription.addObserver((state) async {
|
||||
oneSignalSubscriptionObserver =
|
||||
OneSignal.User.pushSubscription.addObserver((state) async {
|
||||
if (state.current.optedIn) {
|
||||
await _sendSubscriptionId();
|
||||
}
|
||||
});
|
||||
|
||||
// Send the player id when a user allows notifications
|
||||
oneSignalPermissionObserver = OneSignal.Notifications.addPermissionObserver((state) async {
|
||||
oneSignalPermissionObserver =
|
||||
OneSignal.Notifications.addPermissionObserver((state) async {
|
||||
await _sendSubscriptionId();
|
||||
});
|
||||
|
||||
//check if the player id is sent, if not send it again
|
||||
await _sendSubscriptionId();
|
||||
|
||||
oneSignalClickListenerObserver = OneSignal.Notifications.addClickListener((event) async {
|
||||
oneSignalClickListenerObserver =
|
||||
OneSignal.Notifications.addClickListener((event) async {
|
||||
//Once the user clicks on the notification
|
||||
});
|
||||
} catch (err) {
|
||||
@ -173,7 +182,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
if (index == 0) {
|
||||
unselectRoom();
|
||||
} else {
|
||||
selectedRoom = selectedSpace!.rooms![index - 1];
|
||||
selectedRoom = selectedSpace!.subspaces[index - 1];
|
||||
emitSafe(RoomSelected(selectedRoom!));
|
||||
}
|
||||
}
|
||||
@ -188,7 +197,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
if (index <= 0) {
|
||||
unselectRoom();
|
||||
} else {
|
||||
selectedRoom = selectedSpace!.rooms![index - 1];
|
||||
selectedRoom = selectedSpace!.subspaces[index - 1];
|
||||
emitSafe(RoomSelected(selectedRoom!));
|
||||
}
|
||||
}
|
||||
@ -229,7 +238,9 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
Future<bool> joinAUnit(String code) async {
|
||||
try {
|
||||
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? '';
|
||||
var uuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ??
|
||||
'';
|
||||
Map<String, String> body = {'userUuid': uuid, 'inviteCode': code};
|
||||
|
||||
final success = await SpacesAPI.joinUnit(body);
|
||||
@ -247,7 +258,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
fetchUnitsByUserId() async {
|
||||
emitSafe(GetSpacesLoading());
|
||||
try {
|
||||
spaces = await SpacesAPI.getUnitsByUserId();
|
||||
spaces = await SpacesAPI.getSpacesByUserId();
|
||||
} catch (failure) {
|
||||
emitSafe(GetSpacesError("No units found"));
|
||||
return;
|
||||
@ -258,6 +269,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
await fetchRoomsByUnitId(selectedSpace!);
|
||||
emitSafe(GetSpacesSuccess(spaces!));
|
||||
} else {
|
||||
print("here in else");
|
||||
emitSafe(GetSpacesError("No spaces found"));
|
||||
}
|
||||
}
|
||||
@ -265,13 +277,14 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
fetchRoomsByUnitId(SpaceModel space) async {
|
||||
emitSafe(GetSpaceRoomsLoading());
|
||||
try {
|
||||
space.rooms = await SpacesAPI.getRoomsBySpaceId(space.id!);
|
||||
space.subspaces =
|
||||
await SpacesAPI.getSubSpaceBySpaceId(space.community.uuid, space.id);
|
||||
} catch (failure) {
|
||||
emitSafe(GetSpaceRoomsError(failure.toString()));
|
||||
return;
|
||||
}
|
||||
if (space.rooms != null && space.rooms!.isNotEmpty) {
|
||||
emitSafe(GetSpaceRoomsSuccess(space.rooms!));
|
||||
if (space.subspaces != null && space.subspaces!.isNotEmpty) {
|
||||
emitSafe(GetSpaceRoomsSuccess(space.subspaces!));
|
||||
} else {
|
||||
emitSafe(GetSpaceRoomsError("No rooms found"));
|
||||
}
|
||||
@ -347,7 +360,8 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
size: 32,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
foregroundColor:
|
||||
WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(
|
||||
@ -368,7 +382,8 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
NavigationService.navigatorKey.currentContext!
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(const SmartSceneClearEvent());
|
||||
BlocProvider.of<EffectPeriodBloc>(NavigationService.navigatorKey.currentState!.context)
|
||||
BlocProvider.of<EffectPeriodBloc>(
|
||||
NavigationService.navigatorKey.currentState!.context)
|
||||
.add(ResetEffectivePeriod());
|
||||
},
|
||||
),
|
||||
@ -378,7 +393,8 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
size: 28,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
foregroundColor:
|
||||
WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
@ -411,7 +427,8 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
};
|
||||
|
||||
static var bottomNavItems = [
|
||||
defaultBottomNavBarItem(icon: Assets.assetsIconsDashboard, label: 'Dashboard'),
|
||||
defaultBottomNavBarItem(
|
||||
icon: Assets.assetsIconsDashboard, label: 'Dashboard'),
|
||||
// defaultBottomNavBarItem(icon: Assets.assetsIconslayout, label: 'Layout'),
|
||||
defaultBottomNavBarItem(icon: Assets.assetsIconsDevices, label: 'Devices'),
|
||||
defaultBottomNavBarItem(icon: Assets.assetsIconsRoutines, label: 'Routine'),
|
||||
@ -437,7 +454,8 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
void updateDevice(String deviceId) async {
|
||||
try {
|
||||
final response = await DevicesAPI.firmwareDevice(deviceId: deviceId, firmwareVersion: '0');
|
||||
final response = await DevicesAPI.firmwareDevice(
|
||||
deviceId: deviceId, firmwareVersion: '0');
|
||||
if (response['success'] ?? false) {
|
||||
CustomSnackBar.displaySnackBar('No updates available');
|
||||
}
|
||||
@ -445,7 +463,8 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
}
|
||||
}
|
||||
|
||||
BottomNavigationBarItem defaultBottomNavBarItem({required String icon, required String label}) {
|
||||
BottomNavigationBarItem defaultBottomNavBarItem(
|
||||
{required String icon, required String label}) {
|
||||
return BottomNavigationBarItem(
|
||||
icon: SvgPicture.asset(icon),
|
||||
activeIcon: SvgPicture.asset(
|
||||
|
@ -33,7 +33,7 @@ class GetSpacesError extends HomeError {
|
||||
class GetSpaceRoomsLoading extends HomeLoading {}
|
||||
|
||||
class GetSpaceRoomsSuccess extends HomeSuccess {
|
||||
final List<RoomModel> rooms;
|
||||
final List<SubSpaceModel> rooms;
|
||||
|
||||
GetSpaceRoomsSuccess(this.rooms);
|
||||
}
|
||||
@ -50,7 +50,7 @@ class SpaceSelected extends HomeState {
|
||||
}
|
||||
|
||||
class RoomSelected extends HomeState {
|
||||
final RoomModel room;
|
||||
final SubSpaceModel room;
|
||||
|
||||
RoomSelected(this.room);
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||
|
||||
class SpaceModel {
|
||||
final String id;
|
||||
final String name;
|
||||
final Community community;
|
||||
final List<SubSpaceModel> subspaces;
|
||||
late List<SubSpaceModel> subspaces;
|
||||
|
||||
SpaceModel({
|
||||
required this.id,
|
||||
|
@ -27,7 +27,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
if (HomeCubit.getInstance().selectedSpace != null &&
|
||||
HomeCubit.getInstance().spaces!.isNotEmpty) {
|
||||
// fetchGroups(HomeCubit.getInstance().selectedSpace!.id!);
|
||||
for (var room in HomeCubit.getInstance().selectedSpace!.rooms!) {
|
||||
for (var room in HomeCubit.getInstance().selectedSpace!.subspaces!) {
|
||||
fetchDevicesByRoomId(room.id!);
|
||||
}
|
||||
fetchGroups(HomeCubit.getInstance().selectedSpace?.id ?? '');
|
||||
@ -104,8 +104,8 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
List<DeviceModel> get allDevices {
|
||||
List<DeviceModel> devices = [];
|
||||
if (HomeCubit.getInstance().selectedSpace != null &&
|
||||
HomeCubit.getInstance().selectedSpace!.rooms != null) {
|
||||
for (var room in HomeCubit.getInstance().selectedSpace!.rooms!) {
|
||||
HomeCubit.getInstance().selectedSpace!.subspaces != null) {
|
||||
for (var room in HomeCubit.getInstance().selectedSpace!.subspaces!) {
|
||||
if (room.devices != null) {
|
||||
devices.addAll(room.devices!);
|
||||
}
|
||||
@ -275,7 +275,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
deviceId,
|
||||
HomeCubit.getInstance()
|
||||
.selectedSpace!
|
||||
.rooms!
|
||||
.subspaces!
|
||||
.indexOf(HomeCubit.getInstance().selectedRoom!),
|
||||
code: control.code);
|
||||
});
|
||||
@ -308,15 +308,15 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
emitSafe(GetDevicesLoading());
|
||||
int roomIndex =
|
||||
HomeCubit.getInstance().selectedSpace!.rooms!.indexWhere((element) => element.id == roomId);
|
||||
HomeCubit.getInstance().selectedSpace!.subspaces!.indexWhere((element) => element.id == roomId);
|
||||
try {
|
||||
HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices =
|
||||
HomeCubit.getInstance().selectedSpace!.subspaces![roomIndex].devices =
|
||||
await DevicesAPI.getDevicesByRoomId(roomId);
|
||||
} catch (e) {
|
||||
emitSafe(GetDevicesError(e.toString()));
|
||||
return;
|
||||
}
|
||||
final devices = HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices;
|
||||
final devices = HomeCubit.getInstance().selectedSpace!.subspaces![roomIndex].devices;
|
||||
emitSafe(GetDevicesSuccess(devices));
|
||||
|
||||
//get status for each device
|
||||
@ -333,7 +333,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
emitSafe(GetDeviceStatusLoading(code: code));
|
||||
int deviceIndex = HomeCubit.getInstance()
|
||||
.selectedSpace!
|
||||
.rooms![roomIndex]
|
||||
.subspaces![roomIndex]
|
||||
.devices!
|
||||
.indexWhere((element) => element.uuid == deviceUuid);
|
||||
List<StatusModel> statuses = [];
|
||||
@ -346,7 +346,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
emitSafe(GetDeviceStatusError(e.toString()));
|
||||
return;
|
||||
}
|
||||
HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices![deviceIndex].status =
|
||||
HomeCubit.getInstance().selectedSpace!.subspaces![roomIndex].devices![deviceIndex].status =
|
||||
statuses;
|
||||
emitSafe(GetDeviceStatusSuccess(code: code));
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ class DevicesViewBody extends StatelessWidget {
|
||||
groupsList: DevicesCubit.getInstance().allCategories ?? [],
|
||||
),
|
||||
if (HomeCubit.getInstance().selectedSpace != null)
|
||||
if (HomeCubit.getInstance().selectedSpace!.rooms != null)
|
||||
...HomeCubit.getInstance().selectedSpace!.rooms!.map((room) {
|
||||
if (HomeCubit.getInstance().selectedSpace!.subspaces != null)
|
||||
...HomeCubit.getInstance().selectedSpace!.subspaces!.map((room) {
|
||||
return RoomPage(
|
||||
room: room,
|
||||
);
|
||||
@ -95,7 +95,7 @@ class DevicesViewBody extends StatelessWidget {
|
||||
),
|
||||
child: SmoothPageIndicator(
|
||||
controller: HomeCubit.getInstance().devicesPageController,
|
||||
count: HomeCubit.getInstance().selectedSpace!.rooms!.length + 1,
|
||||
count: HomeCubit.getInstance().selectedSpace!.subspaces!.length + 1,
|
||||
effect: const WormEffect(
|
||||
paintStyle: PaintingStyle.stroke,
|
||||
dotHeight: 8,
|
||||
|
@ -1,11 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/room_page_switch.dart';
|
||||
|
||||
class RoomPage extends StatelessWidget {
|
||||
const RoomPage({super.key, required this.room});
|
||||
|
||||
final RoomModel room;
|
||||
final SubSpaceModel room;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -40,12 +40,12 @@ class RoomsSlider extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
if (HomeCubit.getInstance().selectedSpace != null)
|
||||
if (HomeCubit.getInstance().selectedSpace!.rooms != null)
|
||||
...HomeCubit.getInstance().selectedSpace!.rooms!.map(
|
||||
if (HomeCubit.getInstance().selectedSpace!.subspaces != null)
|
||||
...HomeCubit.getInstance().selectedSpace!.subspaces!.map(
|
||||
(room) => InkWell(
|
||||
onTap: () {
|
||||
HomeCubit.getInstance().roomSliderPageChanged(
|
||||
HomeCubit.getInstance().selectedSpace!.rooms!.indexOf(room));
|
||||
HomeCubit.getInstance().selectedSpace!.subspaces!.indexOf(room));
|
||||
},
|
||||
child: TitleMedium(
|
||||
text: room.name!,
|
||||
|
@ -22,7 +22,7 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
void _fetchRoomsAndDevices(FetchRoomsEvent event, Emitter<ManageUnitState> emit) async {
|
||||
try {
|
||||
emit(LoadingState());
|
||||
final roomsList = await SpacesAPI.getRoomsBySpaceId(event.unitId);
|
||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(event.unit.community.uuid, event.unit.id);
|
||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||
} catch (e) {
|
||||
emit(const ErrorState(message: 'Something went wrong'));
|
||||
@ -94,12 +94,12 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
}
|
||||
|
||||
_addNewRoom(AddNewRoom event, Emitter<ManageUnitState> emit) async {
|
||||
Map<String, String> body = {'roomName': event.roomName, 'unitUuid': event.unitId};
|
||||
Map<String, String> body = {'roomName': event.roomName};
|
||||
try {
|
||||
emit(LoadingState());
|
||||
final response = await HomeCreation.createRoom(body);
|
||||
if (response['data']['uuid'] != '') {
|
||||
final roomsList = await SpacesAPI.getRoomsBySpaceId(event.unitId);
|
||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(event.unit.community.uuid, event.unit.id);
|
||||
allDevices = await HomeManagementAPI.fetchDevicesByUserId();
|
||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||
await HomeCubit.getInstance().fetchUnitsByUserId();
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||
|
||||
abstract class ManageUnitEvent extends Equatable {
|
||||
const ManageUnitEvent();
|
||||
@ -12,12 +13,12 @@ class InitialEvent extends ManageUnitEvent {}
|
||||
class LoadingEvent extends ManageUnitEvent {}
|
||||
|
||||
class FetchRoomsEvent extends ManageUnitEvent {
|
||||
final String unitId;
|
||||
final SpaceModel unit;
|
||||
|
||||
const FetchRoomsEvent({required this.unitId});
|
||||
const FetchRoomsEvent({required this.unit});
|
||||
|
||||
@override
|
||||
List<Object> get props => [unitId];
|
||||
List<Object> get props => [unit];
|
||||
}
|
||||
|
||||
class FetchDevicesByRoomIdEvent extends ManageUnitEvent {
|
||||
@ -31,12 +32,12 @@ class FetchDevicesByRoomIdEvent extends ManageUnitEvent {
|
||||
|
||||
class AddNewRoom extends ManageUnitEvent {
|
||||
final String roomName;
|
||||
final String unitId;
|
||||
final SpaceModel unit;
|
||||
|
||||
const AddNewRoom({required this.roomName, required this.unitId});
|
||||
const AddNewRoom({required this.roomName, required this.unit});
|
||||
|
||||
@override
|
||||
List<Object> get props => [roomName, unitId];
|
||||
List<Object> get props => [roomName, unit];
|
||||
}
|
||||
|
||||
class AssignRoomEvent extends ManageUnitEvent {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||
|
||||
abstract class ManageUnitState extends Equatable {
|
||||
const ManageUnitState();
|
||||
@ -14,7 +15,7 @@ class InitialState extends ManageUnitState {}
|
||||
class LoadingState extends ManageUnitState {}
|
||||
|
||||
class FetchRoomsState extends ManageUnitState {
|
||||
final List<RoomModel> roomsList;
|
||||
final List<SubSpaceModel> roomsList;
|
||||
final List<DeviceModel> devicesList;
|
||||
|
||||
const FetchRoomsState({required this.devicesList, required this.roomsList});
|
||||
|
@ -60,7 +60,7 @@ class HomeSettingsView extends StatelessWidget {
|
||||
onTap: () {
|
||||
Navigator.of(context).push(CustomPageRoute(
|
||||
builder: (context) => RoomsView(
|
||||
unitId: space?.id ?? '',
|
||||
unit: space!,
|
||||
)));
|
||||
},
|
||||
child: Container(
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/manage_unit_bloc/manage_unit_bloc.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/manage_unit_bloc/manage_unit_event.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/manage_unit_bloc/manage_unit_state.dart';
|
||||
@ -11,14 +12,14 @@ import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class RoomsView extends StatelessWidget {
|
||||
final String unitId;
|
||||
const RoomsView({super.key, required this.unitId});
|
||||
final SpaceModel unit;
|
||||
const RoomsView({super.key, required this.unit});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
TextEditingController textEditingController = TextEditingController();
|
||||
return BlocProvider(
|
||||
create: (context) => ManageUnitBloc()..add(FetchRoomsEvent(unitId: unitId)),
|
||||
create: (context) => ManageUnitBloc()..add(FetchRoomsEvent(unit:unit )),
|
||||
child: BlocConsumer<ManageUnitBloc, ManageUnitState>(
|
||||
listener: (context, state) {},
|
||||
builder: (context, state) {
|
||||
@ -62,7 +63,7 @@ class RoomsView extends StatelessWidget {
|
||||
MaterialPageRoute(
|
||||
builder: (context) => AssignDeviceView(
|
||||
roomId: state.roomsList[index].id ?? '',
|
||||
unitId: unitId,
|
||||
unitId: unit.id,
|
||||
)),
|
||||
);
|
||||
},
|
||||
@ -100,7 +101,7 @@ class RoomsView extends StatelessWidget {
|
||||
BlocProvider.of<ManageUnitBloc>(context).add(
|
||||
AddNewRoom(
|
||||
roomName: textEditingController.text,
|
||||
unitId: unitId));
|
||||
unit: unit));
|
||||
textEditingController.clear();
|
||||
},
|
||||
child: const Row(
|
||||
|
@ -30,7 +30,7 @@ class _SceneRoomsTabBarDevicesViewState
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
rooms = List.from(HomeCubit.getInstance().selectedSpace?.rooms ?? []);
|
||||
rooms = List.from(HomeCubit.getInstance().selectedSpace?.subspaces ?? []);
|
||||
if (rooms != null) {
|
||||
if (rooms![0].id != '-1') {
|
||||
rooms?.insert(
|
||||
|
@ -148,6 +148,7 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Future<Map<String, dynamic>> assignUserToRoom(Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
|
@ -1,32 +1,47 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||
import 'package:syncrow_app/services/api/http_service.dart';
|
||||
|
||||
class SpacesAPI {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
|
||||
static Future<List<SpaceModel>> getUnitsByUserId() async {
|
||||
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||
static Future<List<SpaceModel>> getSpacesByUserId() async {
|
||||
try {
|
||||
var uuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||
if (uuid == null) throw Exception("User UUID is missing");
|
||||
|
||||
final path = ApiEndpoints.userSpaces.replaceFirst('{userUuid}', uuid);
|
||||
final response = await _httpService.get(
|
||||
path: "${ApiEndpoints.unitUser}$uuid",
|
||||
path: path,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) => SpaceModel.fromJsonList(json),
|
||||
expectedResponseModel: (json) => SpaceModel.fromJsonList(json['data']),
|
||||
);
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
print("Error in getSpacesByUserId: $error");
|
||||
rethrow; // Rethrow the error to be caught by `fetchUnitsByUserId`
|
||||
}
|
||||
}
|
||||
|
||||
static Future<List<RoomModel>> getRoomsBySpaceId(String unitId) async {
|
||||
static Future<List<SubSpaceModel>> getSubSpaceBySpaceId(
|
||||
String communityId, String spaceId) async {
|
||||
final path = ApiEndpoints.listSubspace
|
||||
.replaceFirst('{communityUuid}', communityId)
|
||||
.replaceFirst('{spaceUuid}', spaceId);
|
||||
|
||||
final response = await _httpService.get(
|
||||
path: "${ApiEndpoints.unitChild}$unitId",
|
||||
path: path,
|
||||
queryParameters: {"page": 1, "pageSize": 10},
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<RoomModel> rooms = [];
|
||||
List<SubSpaceModel> rooms = [];
|
||||
for (var room in json['children']) {
|
||||
rooms.add(RoomModel.fromJson(room));
|
||||
rooms.add(SubSpaceModel.fromJson(room));
|
||||
}
|
||||
return rooms;
|
||||
},
|
||||
|
Reference in New Issue
Block a user