fixed space

This commit is contained in:
hannathkadher
2024-10-30 09:56:57 +04:00
parent 5a7ed3ec7c
commit d025da6daf
16 changed files with 114 additions and 76 deletions
@@ -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(