mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 07:27:54 +00:00
getting spaces and rooms from api {null checks}
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||
|
||||
class RoomModel {
|
||||
final String id;
|
||||
final String name;
|
||||
final int? id;
|
||||
final String? name;
|
||||
|
||||
final List<DevicesCategoryModel> categories;
|
||||
final List<DevicesCategoryModel>? categories;
|
||||
|
||||
RoomModel({
|
||||
required this.id,
|
||||
@@ -22,8 +22,8 @@ class RoomModel {
|
||||
|
||||
factory RoomModel.fromJson(Map<String, dynamic> json) {
|
||||
return RoomModel(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
id: json['roomId'],
|
||||
name: json['roomName'],
|
||||
categories: json['devices'],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,17 @@ class DevicesViewBody extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
child: BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
//TODO : move to NavigationCubit
|
||||
return state is DevicesLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: Padding(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
print(
|
||||
"length : ${SpacesCubit.get(context).selectedSpace!.rooms!.length}");
|
||||
//TODO : move to NavigationCubit
|
||||
if (state is DevicesLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: Constants.appBarHeight,
|
||||
bottom: Constants.bottomNavBarHeight,
|
||||
@@ -46,16 +51,21 @@ class DevicesViewBody extends StatelessWidget {
|
||||
},
|
||||
children: [
|
||||
const WizardPage(),
|
||||
...SpacesCubit.get(context)
|
||||
.selectedSpace!
|
||||
.rooms!
|
||||
.map(
|
||||
(room) {
|
||||
return RoomPage(
|
||||
room: room,
|
||||
);
|
||||
},
|
||||
)
|
||||
if (SpacesCubit.get(context).selectedSpace != null)
|
||||
if (SpacesCubit.get(context)
|
||||
.selectedSpace!
|
||||
.rooms !=
|
||||
null)
|
||||
...SpacesCubit.get(context)
|
||||
.selectedSpace!
|
||||
.rooms!
|
||||
.map(
|
||||
(room) {
|
||||
return RoomPage(
|
||||
room: room,
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -66,7 +76,11 @@ class DevicesViewBody extends StatelessWidget {
|
||||
child: SmoothPageIndicator(
|
||||
controller:
|
||||
SpacesCubit.get(context).devicesPageController,
|
||||
count: 3,
|
||||
count: SpacesCubit.get(context)
|
||||
.selectedSpace!
|
||||
.rooms!
|
||||
.length +
|
||||
1,
|
||||
effect: const WormEffect(
|
||||
paintStyle: PaintingStyle.stroke,
|
||||
dotHeight: 8,
|
||||
@@ -77,6 +91,9 @@ class DevicesViewBody extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ class RoomPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<DeviceModel> devices = [];
|
||||
for (var category in room.categories) {
|
||||
for (var category in room.categories ?? []) {
|
||||
devices.addAll(category.devices);
|
||||
}
|
||||
return Padding(
|
||||
|
||||
@@ -40,30 +40,33 @@ class RoomsSlider extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
...SpacesCubit.get(context).selectedSpace!.rooms!.map(
|
||||
(room) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
SpacesCubit.get(context).roomSliderPageChanged(
|
||||
SpacesCubit.get(context)
|
||||
.selectedSpace!
|
||||
.rooms!
|
||||
.indexOf(room));
|
||||
},
|
||||
child: TitleMedium(
|
||||
text: room.name,
|
||||
style: context.titleMedium.copyWith(
|
||||
fontSize: 25,
|
||||
color: SpacesCubit.get(context).selectedRoom == room
|
||||
? ColorsManager.textPrimaryColor
|
||||
: ColorsManager.textPrimaryColor
|
||||
.withOpacity(.2),
|
||||
if (SpacesCubit.get(context).selectedSpace != null)
|
||||
if (SpacesCubit.get(context).selectedSpace!.rooms != null)
|
||||
...SpacesCubit.get(context).selectedSpace!.rooms!.map(
|
||||
(room) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
SpacesCubit.get(context).roomSliderPageChanged(
|
||||
SpacesCubit.get(context)
|
||||
.selectedSpace!
|
||||
.rooms!
|
||||
.indexOf(room));
|
||||
},
|
||||
child: TitleMedium(
|
||||
text: room.name!,
|
||||
style: context.titleMedium.copyWith(
|
||||
fontSize: 25,
|
||||
color: SpacesCubit.get(context).selectedRoom ==
|
||||
room
|
||||
? ColorsManager.textPrimaryColor
|
||||
: ColorsManager.textPrimaryColor
|
||||
.withOpacity(.2),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user