From 33d2bbc91f41660004ccde2fed0f5869aa6c47a1 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Tue, 17 Dec 2024 01:13:36 +0300 Subject: [PATCH] Hide unused widgets --- lib/features/app_layout/bloc/home_cubit.dart | 56 ++--- .../view/widgets/app_bar_home_dropdown.dart | 109 ++++----- .../device_manager_bloc.dart | 41 ++-- .../wh_timer_schedule_screen.dart | 206 +++++++++--------- lib/utils/resource_manager/constants.dart | 10 +- 5 files changed, 218 insertions(+), 204 deletions(-) diff --git a/lib/features/app_layout/bloc/home_cubit.dart b/lib/features/app_layout/bloc/home_cubit.dart index 1a93862..9dd85bf 100644 --- a/lib/features/app_layout/bloc/home_cubit.dart +++ b/lib/features/app_layout/bloc/home_cubit.dart @@ -288,31 +288,31 @@ class HomeCubit extends Cubit { static int pageIndex = 0; static Map> appBarActions = { - 'Dashboard': [ - // IconButton( - // icon: const Icon( - // Icons.add, - // size: 25, - // ), - // style: ButtonStyle( - // foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor), - // ), - // onPressed: () { - // Navigator.push( - // NavigationService.navigatorKey.currentContext!, - // CustomPageRoute( - // builder: (context) => CurtainView( - // curtain: DeviceModel( - // name: "Curtain", - // status: [StatusModel(code: "awd", value: 1)], - // productType: DeviceType.Curtain, - // ), - // ), - // ), - // ); - // }, - // ), - ], + // 'Dashboard': [ + // // IconButton( + // // icon: const Icon( + // // Icons.add, + // // size: 25, + // // ), + // // style: ButtonStyle( + // // foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor), + // // ), + // // onPressed: () { + // // Navigator.push( + // // NavigationService.navigatorKey.currentContext!, + // // CustomPageRoute( + // // builder: (context) => CurtainView( + // // curtain: DeviceModel( + // // name: "Curtain", + // // status: [StatusModel(code: "awd", value: 1)], + // // productType: DeviceType.Curtain, + // // ), + // // ), + // // ), + // // ); + // // }, + // // ), + // ], 'Devices': [ //TODO: to be checked // IconButton( @@ -406,7 +406,7 @@ class HomeCubit extends Cubit { }; static Map appBarLeading = { - 'Dashboard': const AppBarHomeDropdown(), + // 'Dashboard': const AppBarHomeDropdown(), 'Devices': const AppBarHomeDropdown(), 'Routine': const AppBarHomeDropdown(), 'Menu': Padding( @@ -421,7 +421,7 @@ class HomeCubit extends Cubit { }; 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'), @@ -429,7 +429,7 @@ class HomeCubit extends Cubit { ]; final List pages = [ - const DashboardView(), + // const DashboardView(), // const LayoutPage(), BlocProvider( create: (context) => DevicesCubit.getInstance(), diff --git a/lib/features/app_layout/view/widgets/app_bar_home_dropdown.dart b/lib/features/app_layout/view/widgets/app_bar_home_dropdown.dart index ebd4ac3..993625a 100644 --- a/lib/features/app_layout/view/widgets/app_bar_home_dropdown.dart +++ b/lib/features/app_layout/view/widgets/app_bar_home_dropdown.dart @@ -12,62 +12,65 @@ class AppBarHomeDropdown extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return Padding( - padding: const EdgeInsets.only(left: 10, right: 10), - child: DropdownButton( - icon: const Icon( - Icons.expand_more, - color: ColorsManager.textPrimaryColor, - size: 16, - ), - underline: const SizedBox.shrink(), - padding: EdgeInsets.zero, - borderRadius: BorderRadius.circular(20), - value: HomeCubit.getInstance().selectedSpace!.id, - items: HomeCubit.getInstance().spaces!.map((space) { - return DropdownMenuItem( - alignment: AlignmentDirectional.centerStart, - value: space.id, - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - SvgPicture.asset( - Assets.assetsIconsHome, - width: 25, - height: 25, - colorFilter: const ColorFilter.mode( - ColorsManager.textPrimaryColor, - BlendMode.srcIn, + return HomeCubit.getInstance().spaces != null || HomeCubit.getInstance().spaces!.isNotEmpty + ? BlocBuilder( + builder: (context, state) { + return Padding( + padding: const EdgeInsets.only(left: 10, right: 10), + child: DropdownButton( + icon: const Icon( + Icons.expand_more, + color: ColorsManager.textPrimaryColor, + size: 16, + ), + underline: const SizedBox.shrink(), + padding: EdgeInsets.zero, + borderRadius: BorderRadius.circular(20), + value: HomeCubit.getInstance().selectedSpace?.id ?? '', + items: HomeCubit.getInstance().spaces!.map((space) { + return DropdownMenuItem( + alignment: AlignmentDirectional.centerStart, + value: space.id, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + SvgPicture.asset( + Assets.assetsIconsHome, + width: 25, + height: 25, + colorFilter: const ColorFilter.mode( + ColorsManager.textPrimaryColor, + BlendMode.srcIn, + ), + ), + const SizedBox(width: 5), + Flexible( + child: BodyMedium( + text: space.name, + style: context.bodyMedium.copyWith( + fontSize: 15, + color: ColorsManager.textPrimaryColor, + overflow: TextOverflow.ellipsis, + ), + ), + ), + const SizedBox(width: 5), + ], ), - ), - const SizedBox(width: 5), - Flexible( - child: BodyMedium( - text: space.name, - style: context.bodyMedium.copyWith( - fontSize: 15, - color: ColorsManager.textPrimaryColor, - overflow: TextOverflow.ellipsis, - ), - ), - ), - const SizedBox(width: 5), - ], + ); + }).toList(), + onChanged: (value) { + if (value != null) { + HomeCubit.getInstance().changeSelectedSpace(HomeCubit.getInstance() + .spaces! + .firstWhere((element) => element.id == value)); + } + }, ), ); - }).toList(), - onChanged: (value) { - if (value != null) { - HomeCubit.getInstance().changeSelectedSpace( - HomeCubit.getInstance().spaces!.firstWhere((element) => element.id == value)); - } }, - ), - ); - }, - ); + ) + : Container(); } } diff --git a/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart b/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart index 41cab5f..8e984ea 100644 --- a/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart +++ b/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart @@ -6,9 +6,11 @@ import 'package:flutter/material.dart'; import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_event.dart'; import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.dart'; import 'package:syncrow_app/features/devices/model/device_category_model.dart'; +import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/services/api/devices_api.dart'; import 'package:syncrow_app/services/api/home_management_api.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; class DeviceManagerBloc extends Bloc { DeviceManagerBloc() : super(DeviceManagerState.initial()) { @@ -25,14 +27,12 @@ class DeviceManagerBloc extends Bloc { static List? allCategories; - Future _onFetchAllDevices( - FetchAllDevices event, Emitter emit) async { + Future _onFetchAllDevices(FetchAllDevices event, Emitter emit) async { emit(state.copyWith(loading: true)); try { final allDevices = await HomeManagementAPI.fetchDevicesByUnitId(); - emit(state.copyWith(devices: allDevices, loading: false)); + emit(state.copyWith(devices: _getOnlyImplementedDevices(allDevices), loading: false)); } catch (e) { - print(e); emit(state.copyWith(error: e.toString(), loading: false)); } } @@ -46,22 +46,21 @@ class DeviceManagerBloc extends Bloc { spaceUuid: event.unit.id, roomId: event.roomId, ); - emit(state.copyWith(devices: devices, loading: false)); + + emit(state.copyWith(devices: _getOnlyImplementedDevices(devices), loading: false)); } catch (e) { emit(state.copyWith(error: e.toString(), loading: false)); } } - void _onSelectCategory( - SelectCategory event, Emitter emit) { + void _onSelectCategory(SelectCategory event, Emitter emit) { for (var i = 0; i < allCategories!.length; i++) { allCategories![i].isSelected = i == event.index; } emit(state.copyWith(categoryChanged: true)); } - void _onUnselectAllCategories( - UnselectAllCategories event, Emitter emit) { + void _onUnselectAllCategories(UnselectAllCategories event, Emitter emit) { for (var category in allCategories!) { category.isSelected = false; } @@ -105,8 +104,7 @@ class DeviceManagerBloc extends Bloc { _updateDevicesStatus(category, emit); } - void _onTurnOnOffDevice( - TurnOnOffDevice event, Emitter emit) { + void _onTurnOnOffDevice(TurnOnOffDevice event, Emitter emit) { var device = event.device; device.isOnline = !device.isOnline!; DevicesCategoryModel category = allCategories!.firstWhere((category) { @@ -129,8 +127,7 @@ class DeviceManagerBloc extends Bloc { emit(state.copyWith(categoryChanged: true)); // Set category changed state } - void _updateDevicesStatus( - DevicesCategoryModel category, Emitter emit) { + void _updateDevicesStatus(DevicesCategoryModel category, Emitter emit) { if (category.devices != null && category.devices!.isNotEmpty) { bool? tempStatus = category.devices![0].isOnline; for (var device in category.devices!) { @@ -150,10 +147,24 @@ class DeviceManagerBloc extends Bloc { try { final deviceFunctions = await DevicesAPI.deviceFunctions(event.deviceId); - emit(state.copyWith( - functionsLoading: false, deviceFunctions: deviceFunctions)); + emit(state.copyWith(functionsLoading: false, deviceFunctions: deviceFunctions)); } catch (e) { emit(state.copyWith(functionsLoading: false, error: e.toString())); } } + + _getOnlyImplementedDevices(List devices) { + List implementedDevices = []; + for (int i = 0; i < devices.length; i++) { + if (devices[i].productType == DeviceType.AC || + devices[i].productType == DeviceType.DoorLock || + devices[i].productType == DeviceType.Gateway || + devices[i].productType == DeviceType.WallSensor || + devices[i].productType == DeviceType.CeilingSensor || + devices[i].productType == DeviceType.ThreeGang) { + implementedDevices.add(devices[i]); + } + } + return implementedDevices; + } } diff --git a/lib/features/devices/view/widgets/water_heater/wh_timer_schedule_screen.dart b/lib/features/devices/view/widgets/water_heater/wh_timer_schedule_screen.dart index c5ab9ce..5e20cc2 100644 --- a/lib/features/devices/view/widgets/water_heater/wh_timer_schedule_screen.dart +++ b/lib/features/devices/view/widgets/water_heater/wh_timer_schedule_screen.dart @@ -6,9 +6,9 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_app/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/water_heater_bloc/water_heater_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; -import 'package:syncrow_app/features/devices/view/widgets/water_heater/Inching_widget.dart'; -import 'package:syncrow_app/features/devices/view/widgets/water_heater/circulate_list_view.dart'; -import 'package:syncrow_app/features/devices/view/widgets/water_heater/circulate_widget.dart'; +// import 'package:syncrow_app/features/devices/view/widgets/water_heater/Inching_widget.dart'; +// import 'package:syncrow_app/features/devices/view/widgets/water_heater/circulate_list_view.dart'; +// import 'package:syncrow_app/features/devices/view/widgets/water_heater/circulate_widget.dart'; import 'package:syncrow_app/features/shared_widgets/create_schedule.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/schedule_list.dart'; @@ -61,7 +61,7 @@ class WHTimerScheduleScreen extends StatelessWidget { } }, child: DefaultTabController( - length: 4, + length: 2, child: DefaultScaffold( appBar: AppBar( backgroundColor: Colors.transparent, @@ -220,54 +220,54 @@ class WHTimerScheduleScreen extends StatelessWidget { ), ), ), - Tab( - icon: Padding( - padding: const EdgeInsets.only(top: 10), - child: SvgPicture.asset( - Assets.scheduleCirculateIcon, - color: waterHeaterBloc.selectedTabIndex == 2 - ? Colors.white - : ColorsManager.blackColor, - ), - ), - child: Container( - padding: const EdgeInsets.symmetric(vertical: 5), - child: Text( - 'Circulate', - style: context.bodySmall.copyWith( - color: waterHeaterBloc.selectedTabIndex == 2 - ? Colors.white - : ColorsManager.blackColor, - fontSize: 12, - fontWeight: FontWeight.w400, - ), - ), - ), - ), - Tab( - icon: Padding( - padding: const EdgeInsets.only(top: 10), - child: SvgPicture.asset( - Assets.scheduleInchingIcon, - color: waterHeaterBloc.selectedTabIndex == 3 - ? Colors.white - : ColorsManager.blackColor, - ), - ), - child: Container( - padding: const EdgeInsets.symmetric(vertical: 5), - child: Text( - 'Inching', - style: context.bodySmall.copyWith( - color: waterHeaterBloc.selectedTabIndex == 3 - ? Colors.white - : ColorsManager.blackColor, - fontSize: 12, - fontWeight: FontWeight.w400, - ), - ), - ), - ), + // Tab( + // icon: Padding( + // padding: const EdgeInsets.only(top: 10), + // child: SvgPicture.asset( + // Assets.scheduleCirculateIcon, + // color: waterHeaterBloc.selectedTabIndex == 2 + // ? Colors.white + // : ColorsManager.blackColor, + // ), + // ), + // child: Container( + // padding: const EdgeInsets.symmetric(vertical: 5), + // child: Text( + // 'Circulate', + // style: context.bodySmall.copyWith( + // color: waterHeaterBloc.selectedTabIndex == 2 + // ? Colors.white + // : ColorsManager.blackColor, + // fontSize: 12, + // fontWeight: FontWeight.w400, + // ), + // ), + // ), + // ), + // Tab( + // icon: Padding( + // padding: const EdgeInsets.only(top: 10), + // child: SvgPicture.asset( + // Assets.scheduleInchingIcon, + // color: waterHeaterBloc.selectedTabIndex == 3 + // ? Colors.white + // : ColorsManager.blackColor, + // ), + // ), + // child: Container( + // padding: const EdgeInsets.symmetric(vertical: 5), + // child: Text( + // 'Inching', + // style: context.bodySmall.copyWith( + // color: waterHeaterBloc.selectedTabIndex == 3 + // ? Colors.white + // : ColorsManager.blackColor, + // fontSize: 12, + // fontWeight: FontWeight.w400, + // ), + // ), + // ), + // ), ], )), Expanded( @@ -357,57 +357,57 @@ class WHTimerScheduleScreen extends StatelessWidget { ), ), ), - Center( - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - waterHeaterBloc.createCirculate == true - ? CirculateWidget( - endDuration: () { - waterHeaterBloc.add(SelectTimeEvent( - context: context, isEffective: false)); - }, - startDuration: () { - waterHeaterBloc.add(SelectTimeEvent( - context: context, isEffective: false)); - }, - isStartEndTime: true, - startTime: DateTime.now(), - endTime: DateTime.now(), - days: waterHeaterBloc.days, - selectedDays: [], - onToggleStartEndTime: (c) {}, - onTimeChanged: (x, f) {}, - onDaySelected: (p0) {}, - ) - : CirculateListView( - listSchedule: [], // Pass the schedule list here - onDismissed: (scheduleId) { - waterHeaterBloc.listSchedule.removeWhere( - (schedule) => - schedule.scheduleId == scheduleId); - waterHeaterBloc - .add(DeleteScheduleEvent(id: scheduleId)); - }, - onToggleSchedule: (scheduleId, isEnabled) { - waterHeaterBloc.add(ToggleScheduleEvent( - id: scheduleId, - toggle: isEnabled, - )); - }, - ) - ], - ), - ), - Column( - children: [ - SizedBox(height: 20), - Container( - child: InchingWidget(), - ), - ], - ) + // Center( + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.center, + // mainAxisAlignment: MainAxisAlignment.center, + // children: [ + // waterHeaterBloc.createCirculate == true + // ? CirculateWidget( + // endDuration: () { + // waterHeaterBloc.add(SelectTimeEvent( + // context: context, isEffective: false)); + // }, + // startDuration: () { + // waterHeaterBloc.add(SelectTimeEvent( + // context: context, isEffective: false)); + // }, + // isStartEndTime: true, + // startTime: DateTime.now(), + // endTime: DateTime.now(), + // days: waterHeaterBloc.days, + // selectedDays: [], + // onToggleStartEndTime: (c) {}, + // onTimeChanged: (x, f) {}, + // onDaySelected: (p0) {}, + // ) + // : CirculateListView( + // listSchedule: [], // Pass the schedule list here + // onDismissed: (scheduleId) { + // waterHeaterBloc.listSchedule.removeWhere( + // (schedule) => + // schedule.scheduleId == scheduleId); + // waterHeaterBloc + // .add(DeleteScheduleEvent(id: scheduleId)); + // }, + // onToggleSchedule: (scheduleId, isEnabled) { + // waterHeaterBloc.add(ToggleScheduleEvent( + // id: scheduleId, + // toggle: isEnabled, + // )); + // }, + // ) + // ], + // ), + // ), + // Column( + // children: [ + // SizedBox(height: 20), + // Container( + // child: InchingWidget(), + // ), + // ], + // ) ], ), ), diff --git a/lib/utils/resource_manager/constants.dart b/lib/utils/resource_manager/constants.dart index fed4255..998ef97 100644 --- a/lib/utils/resource_manager/constants.dart +++ b/lib/utils/resource_manager/constants.dart @@ -710,11 +710,11 @@ List> menuSections = [ 'color': const Color(0xFF001B72), 'buttons': [ {'title': 'About', 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsAbout, 'page': null}, - { - 'title': 'Privacy Policy', - 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsPrivacyPolicy, - 'page': null - }, + // { + // 'title': 'Privacy Policy', + // 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsPrivacyPolicy, + // 'page': null + // }, { 'title': 'User Agreement', 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsUserAgreement,