Hide unused widgets

This commit is contained in:
Abdullah Alassaf
2024-12-17 01:13:36 +03:00
parent f81880a704
commit 33d2bbc91f
5 changed files with 218 additions and 204 deletions

View File

@ -288,31 +288,31 @@ class HomeCubit extends Cubit<HomeState> {
static int pageIndex = 0; static int pageIndex = 0;
static Map<String, List<Widget>> appBarActions = { static Map<String, List<Widget>> appBarActions = {
'Dashboard': [ // 'Dashboard': [
// IconButton( // // IconButton(
// icon: const Icon( // // icon: const Icon(
// Icons.add, // // Icons.add,
// size: 25, // // size: 25,
// ), // // ),
// style: ButtonStyle( // // style: ButtonStyle(
// foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor), // // foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor),
// ), // // ),
// onPressed: () { // // onPressed: () {
// Navigator.push( // // Navigator.push(
// NavigationService.navigatorKey.currentContext!, // // NavigationService.navigatorKey.currentContext!,
// CustomPageRoute( // // CustomPageRoute(
// builder: (context) => CurtainView( // // builder: (context) => CurtainView(
// curtain: DeviceModel( // // curtain: DeviceModel(
// name: "Curtain", // // name: "Curtain",
// status: [StatusModel(code: "awd", value: 1)], // // status: [StatusModel(code: "awd", value: 1)],
// productType: DeviceType.Curtain, // // productType: DeviceType.Curtain,
// ), // // ),
// ), // // ),
// ), // // ),
// ); // // );
// }, // // },
// ), // // ),
], // ],
'Devices': [ 'Devices': [
//TODO: to be checked //TODO: to be checked
// IconButton( // IconButton(
@ -406,7 +406,7 @@ class HomeCubit extends Cubit<HomeState> {
}; };
static Map<String, Widget?> appBarLeading = { static Map<String, Widget?> appBarLeading = {
'Dashboard': const AppBarHomeDropdown(), // 'Dashboard': const AppBarHomeDropdown(),
'Devices': const AppBarHomeDropdown(), 'Devices': const AppBarHomeDropdown(),
'Routine': const AppBarHomeDropdown(), 'Routine': const AppBarHomeDropdown(),
'Menu': Padding( 'Menu': Padding(
@ -421,7 +421,7 @@ class HomeCubit extends Cubit<HomeState> {
}; };
static var bottomNavItems = [ static var bottomNavItems = [
defaultBottomNavBarItem(icon: Assets.assetsIconsDashboard, label: 'Dashboard'), // defaultBottomNavBarItem(icon: Assets.assetsIconsDashboard, label: 'Dashboard'),
// defaultBottomNavBarItem(icon: Assets.assetsIconslayout, label: 'Layout'), // defaultBottomNavBarItem(icon: Assets.assetsIconslayout, label: 'Layout'),
defaultBottomNavBarItem(icon: Assets.assetsIconsDevices, label: 'Devices'), defaultBottomNavBarItem(icon: Assets.assetsIconsDevices, label: 'Devices'),
defaultBottomNavBarItem(icon: Assets.assetsIconsRoutines, label: 'Routine'), defaultBottomNavBarItem(icon: Assets.assetsIconsRoutines, label: 'Routine'),
@ -429,7 +429,7 @@ class HomeCubit extends Cubit<HomeState> {
]; ];
final List<Widget> pages = [ final List<Widget> pages = [
const DashboardView(), // const DashboardView(),
// const LayoutPage(), // const LayoutPage(),
BlocProvider( BlocProvider(
create: (context) => DevicesCubit.getInstance(), create: (context) => DevicesCubit.getInstance(),

View File

@ -12,62 +12,65 @@ class AppBarHomeDropdown extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<HomeCubit, HomeState>( return HomeCubit.getInstance().spaces != null || HomeCubit.getInstance().spaces!.isNotEmpty
builder: (context, state) { ? BlocBuilder<HomeCubit, HomeState>(
return Padding( builder: (context, state) {
padding: const EdgeInsets.only(left: 10, right: 10), return Padding(
child: DropdownButton( padding: const EdgeInsets.only(left: 10, right: 10),
icon: const Icon( child: DropdownButton(
Icons.expand_more, icon: const Icon(
color: ColorsManager.textPrimaryColor, Icons.expand_more,
size: 16, color: ColorsManager.textPrimaryColor,
), size: 16,
underline: const SizedBox.shrink(), ),
padding: EdgeInsets.zero, underline: const SizedBox.shrink(),
borderRadius: BorderRadius.circular(20), padding: EdgeInsets.zero,
value: HomeCubit.getInstance().selectedSpace!.id, borderRadius: BorderRadius.circular(20),
items: HomeCubit.getInstance().spaces!.map((space) { value: HomeCubit.getInstance().selectedSpace?.id ?? '',
return DropdownMenuItem( items: HomeCubit.getInstance().spaces!.map((space) {
alignment: AlignmentDirectional.centerStart, return DropdownMenuItem(
value: space.id, alignment: AlignmentDirectional.centerStart,
child: Row( value: space.id,
mainAxisAlignment: MainAxisAlignment.start, child: Row(
mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[ mainAxisSize: MainAxisSize.min,
SvgPicture.asset( children: <Widget>[
Assets.assetsIconsHome, SvgPicture.asset(
width: 25, Assets.assetsIconsHome,
height: 25, width: 25,
colorFilter: const ColorFilter.mode( height: 25,
ColorsManager.textPrimaryColor, colorFilter: const ColorFilter.mode(
BlendMode.srcIn, 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), }).toList(),
Flexible( onChanged: (value) {
child: BodyMedium( if (value != null) {
text: space.name, HomeCubit.getInstance().changeSelectedSpace(HomeCubit.getInstance()
style: context.bodyMedium.copyWith( .spaces!
fontSize: 15, .firstWhere((element) => element.id == value));
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));
}
}, },
), )
); : Container();
},
);
} }
} }

View File

@ -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_event.dart';
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.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_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/devices_api.dart';
import 'package:syncrow_app/services/api/home_management_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<DeviceManagerEvent, DeviceManagerState> { class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
DeviceManagerBloc() : super(DeviceManagerState.initial()) { DeviceManagerBloc() : super(DeviceManagerState.initial()) {
@ -25,14 +27,12 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
static List<DevicesCategoryModel>? allCategories; static List<DevicesCategoryModel>? allCategories;
Future<void> _onFetchAllDevices( Future<void> _onFetchAllDevices(FetchAllDevices event, Emitter<DeviceManagerState> emit) async {
FetchAllDevices event, Emitter<DeviceManagerState> emit) async {
emit(state.copyWith(loading: true)); emit(state.copyWith(loading: true));
try { try {
final allDevices = await HomeManagementAPI.fetchDevicesByUnitId(); final allDevices = await HomeManagementAPI.fetchDevicesByUnitId();
emit(state.copyWith(devices: allDevices, loading: false)); emit(state.copyWith(devices: _getOnlyImplementedDevices(allDevices), loading: false));
} catch (e) { } catch (e) {
print(e);
emit(state.copyWith(error: e.toString(), loading: false)); emit(state.copyWith(error: e.toString(), loading: false));
} }
} }
@ -46,22 +46,21 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
spaceUuid: event.unit.id, spaceUuid: event.unit.id,
roomId: event.roomId, roomId: event.roomId,
); );
emit(state.copyWith(devices: devices, loading: false));
emit(state.copyWith(devices: _getOnlyImplementedDevices(devices), loading: false));
} catch (e) { } catch (e) {
emit(state.copyWith(error: e.toString(), loading: false)); emit(state.copyWith(error: e.toString(), loading: false));
} }
} }
void _onSelectCategory( void _onSelectCategory(SelectCategory event, Emitter<DeviceManagerState> emit) {
SelectCategory event, Emitter<DeviceManagerState> emit) {
for (var i = 0; i < allCategories!.length; i++) { for (var i = 0; i < allCategories!.length; i++) {
allCategories![i].isSelected = i == event.index; allCategories![i].isSelected = i == event.index;
} }
emit(state.copyWith(categoryChanged: true)); emit(state.copyWith(categoryChanged: true));
} }
void _onUnselectAllCategories( void _onUnselectAllCategories(UnselectAllCategories event, Emitter<DeviceManagerState> emit) {
UnselectAllCategories event, Emitter<DeviceManagerState> emit) {
for (var category in allCategories!) { for (var category in allCategories!) {
category.isSelected = false; category.isSelected = false;
} }
@ -105,8 +104,7 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
_updateDevicesStatus(category, emit); _updateDevicesStatus(category, emit);
} }
void _onTurnOnOffDevice( void _onTurnOnOffDevice(TurnOnOffDevice event, Emitter<DeviceManagerState> emit) {
TurnOnOffDevice event, Emitter<DeviceManagerState> emit) {
var device = event.device; var device = event.device;
device.isOnline = !device.isOnline!; device.isOnline = !device.isOnline!;
DevicesCategoryModel category = allCategories!.firstWhere((category) { DevicesCategoryModel category = allCategories!.firstWhere((category) {
@ -129,8 +127,7 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
emit(state.copyWith(categoryChanged: true)); // Set category changed state emit(state.copyWith(categoryChanged: true)); // Set category changed state
} }
void _updateDevicesStatus( void _updateDevicesStatus(DevicesCategoryModel category, Emitter<DeviceManagerState> emit) {
DevicesCategoryModel category, Emitter<DeviceManagerState> emit) {
if (category.devices != null && category.devices!.isNotEmpty) { if (category.devices != null && category.devices!.isNotEmpty) {
bool? tempStatus = category.devices![0].isOnline; bool? tempStatus = category.devices![0].isOnline;
for (var device in category.devices!) { for (var device in category.devices!) {
@ -150,10 +147,24 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
try { try {
final deviceFunctions = await DevicesAPI.deviceFunctions(event.deviceId); final deviceFunctions = await DevicesAPI.deviceFunctions(event.deviceId);
emit(state.copyWith( emit(state.copyWith(functionsLoading: false, deviceFunctions: deviceFunctions));
functionsLoading: false, deviceFunctions: deviceFunctions));
} catch (e) { } catch (e) {
emit(state.copyWith(functionsLoading: false, error: e.toString())); emit(state.copyWith(functionsLoading: false, error: e.toString()));
} }
} }
_getOnlyImplementedDevices(List<DeviceModel> devices) {
List<DeviceModel> 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;
}
} }

View File

@ -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_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/water_heater_bloc/water_heater_state.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/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/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_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/circulate_widget.dart';
import 'package:syncrow_app/features/shared_widgets/create_schedule.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/default_scaffold.dart';
import 'package:syncrow_app/features/shared_widgets/schedule_list.dart'; import 'package:syncrow_app/features/shared_widgets/schedule_list.dart';
@ -61,7 +61,7 @@ class WHTimerScheduleScreen extends StatelessWidget {
} }
}, },
child: DefaultTabController( child: DefaultTabController(
length: 4, length: 2,
child: DefaultScaffold( child: DefaultScaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
@ -220,54 +220,54 @@ class WHTimerScheduleScreen extends StatelessWidget {
), ),
), ),
), ),
Tab( // Tab(
icon: Padding( // icon: Padding(
padding: const EdgeInsets.only(top: 10), // padding: const EdgeInsets.only(top: 10),
child: SvgPicture.asset( // child: SvgPicture.asset(
Assets.scheduleCirculateIcon, // Assets.scheduleCirculateIcon,
color: waterHeaterBloc.selectedTabIndex == 2 // color: waterHeaterBloc.selectedTabIndex == 2
? Colors.white // ? Colors.white
: ColorsManager.blackColor, // : ColorsManager.blackColor,
), // ),
), // ),
child: Container( // child: Container(
padding: const EdgeInsets.symmetric(vertical: 5), // padding: const EdgeInsets.symmetric(vertical: 5),
child: Text( // child: Text(
'Circulate', // 'Circulate',
style: context.bodySmall.copyWith( // style: context.bodySmall.copyWith(
color: waterHeaterBloc.selectedTabIndex == 2 // color: waterHeaterBloc.selectedTabIndex == 2
? Colors.white // ? Colors.white
: ColorsManager.blackColor, // : ColorsManager.blackColor,
fontSize: 12, // fontSize: 12,
fontWeight: FontWeight.w400, // fontWeight: FontWeight.w400,
), // ),
), // ),
), // ),
), // ),
Tab( // Tab(
icon: Padding( // icon: Padding(
padding: const EdgeInsets.only(top: 10), // padding: const EdgeInsets.only(top: 10),
child: SvgPicture.asset( // child: SvgPicture.asset(
Assets.scheduleInchingIcon, // Assets.scheduleInchingIcon,
color: waterHeaterBloc.selectedTabIndex == 3 // color: waterHeaterBloc.selectedTabIndex == 3
? Colors.white // ? Colors.white
: ColorsManager.blackColor, // : ColorsManager.blackColor,
), // ),
), // ),
child: Container( // child: Container(
padding: const EdgeInsets.symmetric(vertical: 5), // padding: const EdgeInsets.symmetric(vertical: 5),
child: Text( // child: Text(
'Inching', // 'Inching',
style: context.bodySmall.copyWith( // style: context.bodySmall.copyWith(
color: waterHeaterBloc.selectedTabIndex == 3 // color: waterHeaterBloc.selectedTabIndex == 3
? Colors.white // ? Colors.white
: ColorsManager.blackColor, // : ColorsManager.blackColor,
fontSize: 12, // fontSize: 12,
fontWeight: FontWeight.w400, // fontWeight: FontWeight.w400,
), // ),
), // ),
), // ),
), // ),
], ],
)), )),
Expanded( Expanded(
@ -357,57 +357,57 @@ class WHTimerScheduleScreen extends StatelessWidget {
), ),
), ),
), ),
Center( // Center(
child: Column( // child: Column(
crossAxisAlignment: CrossAxisAlignment.center, // crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, // mainAxisAlignment: MainAxisAlignment.center,
children: [ // children: [
waterHeaterBloc.createCirculate == true // waterHeaterBloc.createCirculate == true
? CirculateWidget( // ? CirculateWidget(
endDuration: () { // endDuration: () {
waterHeaterBloc.add(SelectTimeEvent( // waterHeaterBloc.add(SelectTimeEvent(
context: context, isEffective: false)); // context: context, isEffective: false));
}, // },
startDuration: () { // startDuration: () {
waterHeaterBloc.add(SelectTimeEvent( // waterHeaterBloc.add(SelectTimeEvent(
context: context, isEffective: false)); // context: context, isEffective: false));
}, // },
isStartEndTime: true, // isStartEndTime: true,
startTime: DateTime.now(), // startTime: DateTime.now(),
endTime: DateTime.now(), // endTime: DateTime.now(),
days: waterHeaterBloc.days, // days: waterHeaterBloc.days,
selectedDays: [], // selectedDays: [],
onToggleStartEndTime: (c) {}, // onToggleStartEndTime: (c) {},
onTimeChanged: (x, f) {}, // onTimeChanged: (x, f) {},
onDaySelected: (p0) {}, // onDaySelected: (p0) {},
) // )
: CirculateListView( // : CirculateListView(
listSchedule: [], // Pass the schedule list here // listSchedule: [], // Pass the schedule list here
onDismissed: (scheduleId) { // onDismissed: (scheduleId) {
waterHeaterBloc.listSchedule.removeWhere( // waterHeaterBloc.listSchedule.removeWhere(
(schedule) => // (schedule) =>
schedule.scheduleId == scheduleId); // schedule.scheduleId == scheduleId);
waterHeaterBloc // waterHeaterBloc
.add(DeleteScheduleEvent(id: scheduleId)); // .add(DeleteScheduleEvent(id: scheduleId));
}, // },
onToggleSchedule: (scheduleId, isEnabled) { // onToggleSchedule: (scheduleId, isEnabled) {
waterHeaterBloc.add(ToggleScheduleEvent( // waterHeaterBloc.add(ToggleScheduleEvent(
id: scheduleId, // id: scheduleId,
toggle: isEnabled, // toggle: isEnabled,
)); // ));
}, // },
) // )
], // ],
), // ),
), // ),
Column( // Column(
children: [ // children: [
SizedBox(height: 20), // SizedBox(height: 20),
Container( // Container(
child: InchingWidget(), // child: InchingWidget(),
), // ),
], // ],
) // )
], ],
), ),
), ),

View File

@ -710,11 +710,11 @@ List<Map<String, Object>> menuSections = [
'color': const Color(0xFF001B72), 'color': const Color(0xFF001B72),
'buttons': [ 'buttons': [
{'title': 'About', 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsAbout, 'page': null}, {'title': 'About', 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsAbout, 'page': null},
{ // {
'title': 'Privacy Policy', // 'title': 'Privacy Policy',
'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsPrivacyPolicy, // 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsPrivacyPolicy,
'page': null // 'page': null
}, // },
{ {
'title': 'User Agreement', 'title': 'User Agreement',
'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsUserAgreement, 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsUserAgreement,