Fixed navigation issue

This commit is contained in:
Mohammad Salameh
2024-03-04 15:03:57 +03:00
parent 7ecac02a8a
commit 49b24e14eb
6 changed files with 64 additions and 18 deletions

View File

@ -0,0 +1,20 @@
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 20C0 8.95416 8.95416 0 20 0C31.0458 0 40 8.95416 40 20C40 31.0458 31.0458 40 20 40C8.95416 40 0 31.0458 0 20ZM20 31.9598C26.6052 31.9598 31.9598 26.6052 31.9598 20C31.9598 13.3948 26.6052 8.04016 20 8.04016C13.3948 8.04016 8.04016 13.3948 8.04016 20C8.04016 26.6052 13.3948 31.9598 20 31.9598Z" fill="#83D9FF"/>
<path d="M20 39.9999V31.9598C21.5268 31.9598 22.9858 31.6741 24.3283 31.1526L27.0792 38.7106C24.8779 39.5437 22.4927 39.9999 20 39.9999Z" fill="#3FEFEF"/>
<path d="M24.3287 31.1526C25.7106 30.6158 26.9685 29.8294 28.047 28.8483L33.2182 35.0101C31.4274 36.5875 29.3525 37.8503 27.0796 38.7106L24.3287 31.1526Z" fill="#1DD1D9"/>
<path d="M28.0469 28.8483C29.1141 27.877 30.0052 26.7155 30.6665 25.4166L37.6355 29.4407C36.5033 31.5525 35.0015 33.4382 33.2178 35.0101L28.0469 28.8483Z" fill="#17B5BA"/>
<path d="M31.6322 17.2079L39.5598 15.8099C39.8488 17.1613 40.0001 18.5626 40.0001 20C40.0001 20.9335 39.9357 21.8518 39.8118 22.7518L31.8843 21.3547C31.934 20.9103 31.96 20.4581 31.96 20C31.96 19.0381 31.8464 18.1039 31.6322 17.2079Z" fill="#9BE058"/>
<path d="M30.0234 13.472L36.993 9.448C38.1915 11.3749 39.0719 13.5197 39.5596 15.81L31.632 17.208C31.3094 15.8591 30.7589 14.5997 30.0234 13.472Z" fill="#C0FF66"/>
<path d="M27.317 10.5393L32.4882 4.37659C34.2619 5.79626 35.7887 7.51166 36.9935 9.448L30.0239 13.472C29.2906 12.3493 28.3738 11.3578 27.317 10.5393Z" fill="#FFDF46"/>
<path d="M13.3973 1.11633C15.4649 0.392761 17.6863 0 20.0001 0V8.04016C18.6519 8.04016 17.3564 8.26324 16.1473 8.67432L13.3973 1.11633Z" fill="#FC3E81"/>
<path d="M7.51233 4.37653C9.25824 2.97943 11.2434 1.8689 13.3964 1.11633H13.3973L16.1473 8.67432C14.8845 9.10339 13.7169 9.73847 12.6835 10.5392L7.51233 4.37653Z" fill="#F01054"/>
<path d="M3.0072 9.448C4.21204 7.51166 5.73883 5.79657 7.51251 4.37659L12.6837 10.5393C11.6269 11.3578 10.7101 12.3493 9.97711 13.472L3.0072 9.448Z" fill="#7884EA"/>
<path d="M0.18811 22.7517L8.11566 21.3546C8.27924 22.8024 8.70068 24.1723 9.33362 25.4165L2.36432 29.4406C1.26813 27.3971 0.51648 25.1418 0.18811 22.7517Z" fill="#1685FB"/>
<path d="M2.36438 29.4407L9.33337 25.4166C9.995 26.7155 10.8861 27.877 11.9533 28.8483L6.7821 35.0101C4.99866 33.4382 3.49689 31.5525 2.36438 29.4407Z" fill="#43A3F9"/>
<path d="M6.78235 35.0101L11.9536 28.8483C13.0317 29.8294 14.2897 30.6158 15.6718 31.1526L12.9207 38.7106C10.648 37.8503 8.57312 36.5875 6.78235 35.0101Z" fill="#64BDFF"/>
<path d="M0.440796 15.81C0.928467 13.5197 1.8089 11.3749 3.00732 9.448L9.97693 13.472C9.24146 14.5997 8.69092 15.8591 8.36835 17.208L0.440796 15.81Z" fill="#4A5BE5"/>
<path d="M30.6663 25.4165C31.2989 24.172 31.7203 22.8024 31.8839 21.3546L39.8115 22.7517C39.4831 25.1418 38.7314 27.3971 37.6353 29.4406L30.6663 25.4165Z" fill="#1CC939"/>
<path d="M0 20C0 18.5626 0.151367 17.1613 0.440369 15.8099L8.36792 17.2079C8.15369 18.1039 8.04016 19.0381 8.04016 20C8.04016 20.4581 8.0661 20.9103 8.11584 21.3547L0.188293 22.7518C0.0643921 21.8518 0 20.9335 0 20Z" fill="#364EC6"/>
<path d="M23.8527 8.67432L26.6035 1.11633C28.7565 1.8689 30.742 2.97943 32.4876 4.37683L27.3167 10.5392C26.2831 9.73847 25.1152 9.10339 23.8527 8.67432Z" fill="#F9B200"/>
<path d="M20 8.04016V0C22.3138 0 24.5361 0.392761 26.6037 1.11633L23.8525 8.67432C22.6437 8.26324 21.3483 8.04016 20 8.04016Z" fill="#FD6096"/>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

20
assets/icons/kalvin.svg Normal file
View File

@ -0,0 +1,20 @@
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 20C0 8.95416 8.95416 0 20 0C31.0458 0 40 8.95416 40 20C40 31.0458 31.0458 40 20 40C8.95416 40 0 31.0458 0 20ZM20 31.9598C26.6052 31.9598 31.9598 26.6052 31.9598 20C31.9598 13.3948 26.6052 8.04016 20 8.04016C13.3948 8.04016 8.04016 13.3948 8.04016 20C8.04016 26.6052 13.3948 31.9598 20 31.9598Z" fill="#F2F2F2"/>
<path d="M20 39.9999V31.9598C21.5268 31.9598 22.9858 31.6741 24.3283 31.1526L27.0792 38.7106C24.8779 39.5437 22.4927 39.9999 20 39.9999Z" fill="#FCFAE0"/>
<path d="M24.3287 31.1526C25.7106 30.6158 26.9685 29.8294 28.047 28.8483L33.2182 35.0101C31.4274 36.5875 29.3525 37.8503 27.0796 38.7106L24.3287 31.1526Z" fill="#FCFAE0"/>
<path d="M28.0469 28.8483C29.1141 27.877 30.0052 26.7155 30.6665 25.4166L37.6355 29.4407C36.5033 31.5525 35.0015 33.4382 33.2178 35.0101L28.0469 28.8483Z" fill="#FCFAE0"/>
<path d="M31.6322 17.2079L39.5598 15.8099C39.8488 17.1613 40.0001 18.5626 40.0001 20C40.0001 20.9335 39.9357 21.8518 39.8118 22.7518L31.8843 21.3547C31.934 20.9103 31.96 20.4581 31.96 20C31.96 19.0381 31.8464 18.1039 31.6322 17.2079Z" fill="#FAE63A"/>
<path d="M30.0234 13.472L36.993 9.448C38.1915 11.3749 39.0719 13.5197 39.5596 15.81L31.632 17.208C31.3094 15.8591 30.7589 14.5997 30.0234 13.472Z" fill="#FAE63A"/>
<path d="M27.317 10.5393L32.4882 4.37659C34.2619 5.79626 35.7887 7.51166 36.9935 9.448L30.0239 13.472C29.2906 12.3493 28.3738 11.3578 27.317 10.5393Z" fill="#FDC242"/>
<path d="M13.3973 1.11633C15.4649 0.392761 17.6863 0 20.0001 0V8.04016C18.6519 8.04016 17.3564 8.26324 16.1473 8.67432L13.3973 1.11633Z" fill="#7FE1FE"/>
<path d="M7.51233 4.37653C9.25824 2.97943 11.2434 1.8689 13.3964 1.11633H13.3973L16.1473 8.67432C14.8845 9.10339 13.7169 9.73847 12.6835 10.5392L7.51233 4.37653Z" fill="#7FE1FE"/>
<path d="M3.0072 9.448C4.21204 7.51166 5.73883 5.79657 7.51251 4.37659L12.6837 10.5393C11.6269 11.3578 10.7101 12.3493 9.97711 13.472L3.0072 9.448Z" fill="#7FE1FE"/>
<path d="M0.18811 22.7517L8.11566 21.3546C8.27924 22.8024 8.70068 24.1723 9.33362 25.4165L2.36432 29.4406C1.26813 27.3971 0.51648 25.1418 0.18811 22.7517Z" fill="#CBF1FA"/>
<path d="M2.36438 29.4407L9.33337 25.4166C9.995 26.7155 10.8861 27.877 11.9533 28.8483L6.7821 35.0101C4.99866 33.4382 3.49689 31.5525 2.36438 29.4407Z" fill="#F2F2F2"/>
<path d="M6.78235 35.0101L11.9536 28.8483C13.0317 29.8294 14.2897 30.6158 15.6718 31.1526L12.9207 38.7106C10.648 37.8503 8.57312 36.5875 6.78235 35.0101Z" fill="#F2F2F2"/>
<path d="M0.440796 15.81C0.928467 13.5197 1.8089 11.3749 3.00732 9.448L9.97693 13.472C9.24146 14.5997 8.69092 15.8591 8.36835 17.208L0.440796 15.81Z" fill="#CBF1FA"/>
<path d="M30.6663 25.4165C31.2989 24.172 31.7203 22.8024 31.8839 21.3546L39.8115 22.7517C39.4831 25.1418 38.7314 27.3971 37.6353 29.4406L30.6663 25.4165Z" fill="#FAE63A"/>
<path d="M0 20C0 18.5626 0.151367 17.1613 0.440369 15.8099L8.36792 17.2079C8.15369 18.1039 8.04016 19.0381 8.04016 20C8.04016 20.4581 8.0661 20.9103 8.11584 21.3547L0.188293 22.7518C0.0643921 21.8518 0 20.9335 0 20Z" fill="#CBF1FA"/>
<path d="M23.8527 8.67432L26.6035 1.11633C28.7565 1.8689 30.742 2.97943 32.4876 4.37683L27.3167 10.5392C26.2831 9.73847 25.1152 9.10339 23.8527 8.67432Z" fill="#FDC242"/>
<path d="M20 8.04016V0C22.3138 0 24.5361 0.392761 26.6037 1.11633L23.8525 8.67432C22.6437 8.26324 21.3483 8.04016 20 8.04016Z" fill="#FDC242"/>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -21,7 +21,7 @@ class DefaultNavBar extends StatelessWidget {
onTap: (int index) { onTap: (int index) {
cubit.updatePageIndex(index, context); cubit.updatePageIndex(index, context);
if (DevicesCubit.get(context).chosenCategoryView != null) { if (DevicesCubit.get(context).chosenCategoryView != null) {
Navigator.pop(context); DevicesCubit().clearCategoriesSelection(context);
} }
}, },
currentIndex: cubit.getPageIndex, currentIndex: cubit.getPageIndex,

View File

@ -209,7 +209,7 @@ class DevicesCubit extends Cubit<DevicesState> {
), ),
]; ];
void selectCategory(int index) { selectCategory(int index) {
for (var i = 0; i < categories.length; i++) { for (var i = 0; i < categories.length; i++) {
if (i == index) { if (i == index) {
categories[i].isSelected = true; categories[i].isSelected = true;
@ -220,6 +220,13 @@ class DevicesCubit extends Cubit<DevicesState> {
emit(DevicesCategoryChanged()); emit(DevicesCategoryChanged());
} }
unselectAllCategories() {
for (var category in categories) {
category.isSelected = false;
}
emit(DevicesCategoryChanged());
}
Widget? get chosenCategoryView { Widget? get chosenCategoryView {
for (var category in categories) { for (var category in categories) {
if (category.isSelected) { if (category.isSelected) {
@ -229,7 +236,7 @@ class DevicesCubit extends Cubit<DevicesState> {
return null; return null;
} }
void selectDevice(DeviceModel device) { selectDevice(DeviceModel device) {
for (var category in categories) { for (var category in categories) {
for (var device in category.devices) { for (var device in category.devices) {
if (device.isSelected) { if (device.isSelected) {
@ -254,7 +261,7 @@ class DevicesCubit extends Cubit<DevicesState> {
return null; return null;
} }
void changeCategorySwitchValue(DevicesCategoryModel category) { changeCategorySwitchValue(DevicesCategoryModel category) {
if (category.devicesStatus != null) { if (category.devicesStatus != null) {
category.devicesStatus = !category.devicesStatus!; category.devicesStatus = !category.devicesStatus!;
for (var device in category.devices) { for (var device in category.devices) {
@ -270,7 +277,7 @@ class DevicesCubit extends Cubit<DevicesState> {
emit(CategorySwitchChanged()); emit(CategorySwitchChanged());
} }
void turnOnOffDevice(DeviceModel device) { turnOnOffDevice(DeviceModel device) {
device.status = !device.status!; device.status = !device.status!;
DevicesCategoryModel category = DevicesCategoryModel category =
categories.firstWhere((category) => category.devices.contains(device)); categories.firstWhere((category) => category.devices.contains(device));
@ -278,7 +285,7 @@ class DevicesCubit extends Cubit<DevicesState> {
emit(DeviceSwitchChanged()); emit(DeviceSwitchChanged());
} }
void updateDevicesStatus(DevicesCategoryModel category) { updateDevicesStatus(DevicesCategoryModel category) {
bool? tempStatus = category.devices[0].status; bool? tempStatus = category.devices[0].status;
for (var ac in category.devices) { for (var ac in category.devices) {
//check if there any ac have a different status than the initial ==> turn off the universal switch //check if there any ac have a different status than the initial ==> turn off the universal switch
@ -292,7 +299,7 @@ class DevicesCubit extends Cubit<DevicesState> {
} }
} }
void turnAllDevicesOff(DevicesCategoryModel category) { turnAllDevicesOff(DevicesCategoryModel category) {
for (var device in category.devices) { for (var device in category.devices) {
device.status = false; device.status = false;
} }
@ -300,7 +307,7 @@ class DevicesCubit extends Cubit<DevicesState> {
emit(CategorySwitchChanged()); emit(CategorySwitchChanged());
} }
void turnAllDevicesOn(DevicesCategoryModel category) { turnAllDevicesOn(DevicesCategoryModel category) {
for (var device in category.devices) { for (var device in category.devices) {
device.status = true; device.status = true;
} }
@ -308,7 +315,7 @@ class DevicesCubit extends Cubit<DevicesState> {
emit(CategorySwitchChanged()); emit(CategorySwitchChanged());
} }
void areAllDevicesOff(DevicesCategoryModel category) { areAllDevicesOff(DevicesCategoryModel category) {
for (var device in category.devices) { for (var device in category.devices) {
if (device.status ?? false) { if (device.status ?? false) {
category.devicesStatus = false; category.devicesStatus = false;
@ -318,12 +325,15 @@ class DevicesCubit extends Cubit<DevicesState> {
} }
} }
static void clearCategoriesSelection() { clearCategoriesSelection(BuildContext context) {
for (var category in categories) { for (var category in categories) {
category.isSelected = false; category.isSelected = false;
for (var device in category.devices) { for (var device in category.devices) {
device.isSelected = false; device.isSelected = false;
} }
} }
Navigator.popUntil(context, (route) => route.isFirst);
emit(DevicesCategoryChanged());
} }
} }

View File

@ -9,6 +9,10 @@ import '../../bloc/devices_cubit.dart';
import 'switches.dart'; import 'switches.dart';
class DevicesViewBody extends StatelessWidget { class DevicesViewBody extends StatelessWidget {
const DevicesViewBody({
super.key,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return BlocProvider(
@ -127,8 +131,4 @@ class DevicesViewBody extends StatelessWidget {
), ),
); );
} }
const DevicesViewBody({
super.key,
});
} }

View File

@ -1,7 +1,6 @@
// ignore_for_file: avoid_print // ignore_for_file: avoid_print
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
class MyBlocObserver extends BlocObserver { class MyBlocObserver extends BlocObserver {
@override @override
@ -25,9 +24,6 @@ class MyBlocObserver extends BlocObserver {
@override @override
void onClose(BlocBase bloc) { void onClose(BlocBase bloc) {
super.onClose(bloc); super.onClose(bloc);
if (bloc is DevicesCubit) {
DevicesCubit.clearCategoriesSelection();
}
print('onClose -- ${bloc.runtimeType}'); print('onClose -- ${bloc.runtimeType}');
} }
} }