fetch groups

This commit is contained in:
Mohammad Salameh
2024-03-18 11:46:27 +03:00
parent 65cbf10485
commit 13e80fbad7
20 changed files with 273 additions and 164 deletions
@@ -23,8 +23,6 @@ class DevicesViewBody extends StatelessWidget {
builder: (context, state) {
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());
@@ -51,15 +49,9 @@ class DevicesViewBody extends StatelessWidget {
},
children: [
const WizardPage(),
if (SpacesCubit.get(context).selectedSpace != null)
if (SpacesCubit.get(context)
.selectedSpace!
.rooms !=
null)
...SpacesCubit.get(context)
.selectedSpace!
.rooms!
.map(
if (SpacesCubit.selectedSpace != null)
if (SpacesCubit.selectedSpace!.rooms != null)
...SpacesCubit.selectedSpace!.rooms!.map(
(room) {
return RoomPage(
room: room,
@@ -76,11 +68,7 @@ class DevicesViewBody extends StatelessWidget {
child: SmoothPageIndicator(
controller:
SpacesCubit.get(context).devicesPageController,
count: SpacesCubit.get(context)
.selectedSpace!
.rooms!
.length +
1,
count: SpacesCubit.selectedSpace!.rooms!.length + 1,
effect: const WormEffect(
paintStyle: PaintingStyle.stroke,
dotHeight: 8,
@@ -26,6 +26,7 @@ class LightSwitch extends StatelessWidget {
DevicesCubit.get(context)
.deviceControl(control)
.then((value) {
print('Device control response: $value');
if (control.value ?? true) {
control.value = false;
} else {
@@ -25,26 +25,65 @@ class LightSwitchesBody extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
LightSwitch(
control: DeviceControlModel(
deviceId: 'bfe10693d4fd263206ocq9',
code: 'switch_1',
value: true,
),
Column(
children: [
LightSwitch(
control: DeviceControlModel(
deviceId: 'bfe10693d4fd263206ocq9',
code: 'switch_1',
value: true,
),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Bedside Light",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
LightSwitch(
control: DeviceControlModel(
deviceId: 'bfe10693d4fd263206ocq9',
code: 'switch_2',
value: true,
),
Column(
children: [
LightSwitch(
control: DeviceControlModel(
deviceId: 'bfe10693d4fd263206ocq9',
code: 'switch_2',
value: true,
),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Ceiling Light",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
LightSwitch(
control: DeviceControlModel(
deviceId: 'bfe10693d4fd263206ocq9',
code: 'switch_3',
value: true,
),
Column(
children: [
LightSwitch(
control: DeviceControlModel(
deviceId: 'bfe10693d4fd263206ocq9',
code: 'switch_3',
value: true,
),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Spotlight",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
],
),
@@ -40,33 +40,29 @@ class RoomsSlider extends StatelessWidget {
),
),
),
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),
),
),
if (SpacesCubit.selectedSpace != null)
if (SpacesCubit.selectedSpace!.rooms != null)
...SpacesCubit.selectedSpace!.rooms!.map(
(room) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: InkWell(
onTap: () {
SpacesCubit.get(context).roomSliderPageChanged(
SpacesCubit.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),
),
),
)
),
),
)
],
),
);
@@ -18,68 +18,72 @@ class WizartSwitches extends StatelessWidget {
Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) {
return GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
childAspectRatio: 1.5,
),
padding: const EdgeInsets.only(top: 10),
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: DevicesCubit.allCategories.length,
itemBuilder: (_, index) {
return InkWell(
onTap: () {
DevicesCubit.get(context).selectCategory(index);
//Navigate to the chosen category view without animation
return state is DevicesLoading
? const Center(child: CircularProgressIndicator())
: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
childAspectRatio: 1.5,
),
padding: const EdgeInsets.only(top: 10),
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: DevicesCubit.allCategories.length,
itemBuilder: (_, index) {
return InkWell(
onTap: () {
DevicesCubit.get(context).selectCategory(index);
//Navigate to the chosen category view without animation
Navigator.push(context, CustomPageRoute(builder: (context) {
return DevicesCubit.get(context).chosenCategoryView!;
}));
},
child: DefaultContainer(
child: Padding(
padding: const EdgeInsets.only(top: 10, right: 10, left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SvgPicture.asset(
DevicesCubit.allCategories[index].icon!,
fit: BoxFit.contain,
),
CustomSwitch(
category: DevicesCubit.allCategories[index],
),
],
),
Expanded(
child: FittedBox(
fit: BoxFit.scaleDown,
child: BodyLarge(
text: DevicesCubit.allCategories[index].name!,
style: context.bodyLarge.copyWith(
fontWeight: FontWeight.bold,
height: 0,
fontSize: 24,
color: Colors.grey,
Navigator.push(context,
CustomPageRoute(builder: (context) {
return DevicesCubit.get(context).chosenCategoryView!;
}));
},
child: DefaultContainer(
child: Padding(
padding:
const EdgeInsets.only(top: 10, right: 10, left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SvgPicture.asset(
DevicesCubit.allCategories[index].icon!,
fit: BoxFit.contain,
),
CustomSwitch(
category: DevicesCubit.allCategories[index],
),
],
),
),
Expanded(
child: FittedBox(
fit: BoxFit.scaleDown,
child: BodyLarge(
text: DevicesCubit.allCategories[index].name!,
style: context.bodyLarge.copyWith(
fontWeight: FontWeight.bold,
height: 0,
fontSize: 24,
color: Colors.grey,
),
),
),
),
],
),
),
],
),
),
),
);
},
);
),
);
},
);
},
);
}