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
@@ -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;
}
}
@@ -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(),
// ),
// ],
// )
],
),
),