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 Map<String, List<Widget>> 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<HomeState> {
};
static Map<String, Widget?> appBarLeading = {
'Dashboard': const AppBarHomeDropdown(),
// 'Dashboard': const AppBarHomeDropdown(),
'Devices': const AppBarHomeDropdown(),
'Routine': const AppBarHomeDropdown(),
'Menu': Padding(
@ -421,7 +421,7 @@ class HomeCubit extends Cubit<HomeState> {
};
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<HomeState> {
];
final List<Widget> pages = [
const DashboardView(),
// const DashboardView(),
// const LayoutPage(),
BlocProvider(
create: (context) => DevicesCubit.getInstance(),

View File

@ -12,62 +12,65 @@ class AppBarHomeDropdown extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<HomeCubit, HomeState>(
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: <Widget>[
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<HomeCubit, HomeState>(
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: <Widget>[
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();
}
}

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_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<DeviceManagerEvent, DeviceManagerState> {
DeviceManagerBloc() : super(DeviceManagerState.initial()) {
@ -25,14 +27,12 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
static List<DevicesCategoryModel>? allCategories;
Future<void> _onFetchAllDevices(
FetchAllDevices event, Emitter<DeviceManagerState> emit) async {
Future<void> _onFetchAllDevices(FetchAllDevices event, Emitter<DeviceManagerState> 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<DeviceManagerEvent, DeviceManagerState> {
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<DeviceManagerState> emit) {
void _onSelectCategory(SelectCategory event, Emitter<DeviceManagerState> 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<DeviceManagerState> emit) {
void _onUnselectAllCategories(UnselectAllCategories event, Emitter<DeviceManagerState> emit) {
for (var category in allCategories!) {
category.isSelected = false;
}
@ -105,8 +104,7 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
_updateDevicesStatus(category, emit);
}
void _onTurnOnOffDevice(
TurnOnOffDevice event, Emitter<DeviceManagerState> emit) {
void _onTurnOnOffDevice(TurnOnOffDevice event, Emitter<DeviceManagerState> emit) {
var device = event.device;
device.isOnline = !device.isOnline!;
DevicesCategoryModel category = allCategories!.firstWhere((category) {
@ -129,8 +127,7 @@ class DeviceManagerBloc extends Bloc<DeviceManagerEvent, DeviceManagerState> {
emit(state.copyWith(categoryChanged: true)); // Set category changed state
}
void _updateDevicesStatus(
DevicesCategoryModel category, Emitter<DeviceManagerState> emit) {
void _updateDevicesStatus(DevicesCategoryModel category, Emitter<DeviceManagerState> 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<DeviceManagerEvent, DeviceManagerState> {
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<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_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(),
// ),
// ],
// )
],
),
),

View File

@ -710,11 +710,11 @@ List<Map<String, Object>> 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,