Added three gang bloc, event, state, and model

This commit is contained in:
Abdullah Alassaf
2024-05-21 01:51:53 +03:00
parent 7d4ce7f7b3
commit 008ba8be32
18 changed files with 582 additions and 455 deletions

View File

@ -1,6 +1,7 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/model/ac_model.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/status_model.dart';

View File

@ -1,5 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:syncrow_app/features/devices/model/status_model.dart';
import 'package:syncrow_app/features/devices/model/ac_model.dart';
abstract class AcsState extends Equatable {
const AcsState();

View File

@ -0,0 +1,33 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/status_model.dart';
import 'package:syncrow_app/features/devices/model/three_gang_model.dart';
import 'package:syncrow_app/services/api/devices_api.dart';
class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
final String threeGangId;
late DeviceModel deviceModel;
late ThreeGangModel deviceStatus;
ThreeGangBloc({required this.threeGangId}) : super(InitialState()) {
on<InitialEvent>(_fetchThreeGangStatus);
}
void _fetchThreeGangStatus(InitialEvent event, Emitter<ThreeGangState> emit) async {
emit(LoadingState());
try {
var response = await DevicesAPI.getDeviceStatus(threeGangId);
List<StatusModel> statusModelList = [];
for (var status in response['status']) {
statusModelList.add(StatusModel.fromJson(status));
}
deviceStatus = ThreeGangModel.fromJson(statusModelList);
emit(UpdateState(threeGangModel: deviceStatus));
} catch (e) {
emit(FailedState(error: e.toString()));
return;
}
}
}

View File

@ -0,0 +1,14 @@
import 'package:equatable/equatable.dart';
abstract class ThreeGangEvent extends Equatable {
const ThreeGangEvent();
@override
List<Object> get props => [];
}
class LoadingEvent extends ThreeGangEvent {}
class InitialEvent extends ThreeGangEvent {}
class ChangeStatusEvent extends ThreeGangEvent {}

View File

@ -0,0 +1,30 @@
import 'package:equatable/equatable.dart';
import 'package:syncrow_app/features/devices/model/three_gang_model.dart';
class ThreeGangState extends Equatable {
const ThreeGangState();
@override
List<Object> get props => [];
}
class InitialState extends ThreeGangState {}
class LoadingState extends ThreeGangState {}
class UpdateState extends ThreeGangState {
final ThreeGangModel threeGangModel;
const UpdateState({required this.threeGangModel});
@override
List<Object> get props => [threeGangModel];
}
class FailedState extends ThreeGangState {
final String error;
const FailedState({required this.error});
@override
List<Object> get props => [error];
}

View File

@ -0,0 +1,81 @@
import 'package:syncrow_app/features/devices/model/status_model.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class AcStatusModel {
bool acSwitch;
String modeString;
int tempSet;
int currentTemp;
String fanSpeedsString;
bool childLock;
late TempModes acMode;
late FanSpeeds acFanSpeed;
AcStatusModel(
{required this.acSwitch,
required this.modeString,
required this.tempSet,
required this.currentTemp,
required this.fanSpeedsString,
required this.childLock}) {
acMode = getACMode(modeString);
acFanSpeed = getFanSpeed(fanSpeedsString);
}
factory AcStatusModel.fromJson(List<StatusModel> jsonList) {
late bool _acSwitch;
late String _mode;
late int _tempSet;
late int _currentTemp;
late String _fanSpeeds;
late bool _childLock;
for (int i = 0; i < jsonList.length; i++) {
if (jsonList[i].code == 'switch') {
_acSwitch = jsonList[i].value ?? false;
} else if (jsonList[i].code == 'mode') {
_mode = jsonList[i].value ?? TempModes.cold;
} else if (jsonList[i].code == 'temp_set') {
_tempSet = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'temp_current') {
_currentTemp = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'level') {
_fanSpeeds = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'child_lock') {
_childLock = jsonList[i].value ?? false;
}
}
return AcStatusModel(
acSwitch: _acSwitch,
modeString: _mode,
tempSet: _tempSet,
currentTemp: _currentTemp,
fanSpeedsString: _fanSpeeds,
childLock: _childLock);
}
static TempModes getACMode(String value) {
if (value == 'cold') {
return TempModes.cold;
} else if (value == 'hot') {
return TempModes.hot;
} else if (value == 'wind') {
return TempModes.wind;
} else {
return TempModes.cold;
}
}
static FanSpeeds getFanSpeed(String value) {
if (value == 'low') {
return FanSpeeds.low;
} else if (value == 'middle') {
return FanSpeeds.middle;
} else if (value == 'high') {
return FanSpeeds.high;
} else if (value == 'auto') {
return FanSpeeds.auto;
} else {
return FanSpeeds.auto;
}
}
}

View File

@ -1,84 +1,3 @@
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class AcStatusModel {
bool acSwitch;
String modeString;
int tempSet;
int currentTemp;
String fanSpeedsString;
bool childLock;
late TempModes acMode;
late FanSpeeds acFanSpeed;
AcStatusModel(
{required this.acSwitch,
required this.modeString,
required this.tempSet,
required this.currentTemp,
required this.fanSpeedsString,
required this.childLock}) {
acMode = getACMode(modeString);
acFanSpeed = getFanSpeed(fanSpeedsString);
}
factory AcStatusModel.fromJson(List<StatusModel> jsonList) {
late bool _acSwitch;
late String _mode;
late int _tempSet;
late int _currentTemp;
late String _fanSpeeds;
late bool _childLock;
for (int i = 0; i < jsonList.length; i++) {
if (jsonList[i].code == 'switch') {
_acSwitch = jsonList[i].value ?? false;
} else if (jsonList[i].code == 'mode') {
_mode = jsonList[i].value ?? TempModes.cold;
} else if (jsonList[i].code == 'temp_set') {
_tempSet = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'temp_current') {
_currentTemp = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'level') {
_fanSpeeds = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'child_lock') {
_childLock = jsonList[i].value ?? false;
}
}
return AcStatusModel(
acSwitch: _acSwitch,
modeString: _mode,
tempSet: _tempSet,
currentTemp: _currentTemp,
fanSpeedsString: _fanSpeeds,
childLock: _childLock);
}
static TempModes getACMode(String value) {
if (value == 'cold') {
return TempModes.cold;
} else if (value == 'hot') {
return TempModes.hot;
} else if (value == 'wind') {
return TempModes.wind;
} else {
return TempModes.cold;
}
}
static FanSpeeds getFanSpeed(String value) {
if (value == 'low') {
return FanSpeeds.low;
} else if (value == 'middle') {
return FanSpeeds.middle;
} else if (value == 'high') {
return FanSpeeds.high;
} else if (value == 'auto') {
return FanSpeeds.auto;
} else {
return FanSpeeds.auto;
}
}
}
class StatusModel {
String? code;
dynamic value;

View File

@ -0,0 +1,50 @@
import 'package:syncrow_app/features/devices/model/status_model.dart';
class ThreeGangModel {
bool firstSwitch;
bool secondSwitch;
bool thirdSwitch;
int firstCountDown;
int secondCountDown;
int thirdCountDown;
ThreeGangModel(
{required this.firstSwitch,
required this.secondSwitch,
required this.thirdSwitch,
required this.firstCountDown,
required this.secondCountDown,
required this.thirdCountDown});
factory ThreeGangModel.fromJson(List<StatusModel> jsonList) {
late bool _firstSwitch;
late bool _secondSwitch;
late bool _thirdSwitch;
late int _firstCount;
late int _secondCount;
late int _thirdCount;
for (int i = 0; i < jsonList.length; i++) {
if (jsonList[i].code == 'switch_1') {
_firstSwitch = jsonList[i].value ?? false;
} else if (jsonList[i].code == 'switch_2') {
_secondSwitch = jsonList[i].value ?? false;
} else if (jsonList[i].code == 'switch_3') {
_thirdSwitch = jsonList[i].value ?? false;
} else if (jsonList[i].code == 'countdown_1') {
_firstCount = jsonList[i].value ?? 0;
} else if (jsonList[i].code == 'countdown_2') {
_secondCount = jsonList[i].value ?? 0;
} else if (jsonList[i].code == 'countdown_3') {
_thirdCount = jsonList[i].value ?? 0;
}
}
return ThreeGangModel(
firstSwitch: _firstSwitch,
secondSwitch: _secondSwitch,
thirdSwitch: _thirdSwitch,
firstCountDown: _firstCount,
secondCountDown: _secondCount,
thirdCountDown: _thirdCount);
}
}

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_mode_control_unit.dart';

View File

@ -3,7 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:sleek_circular_slider/sleek_circular_slider.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface.dart';

View File

@ -17,7 +17,6 @@ import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_
import 'package:syncrow_app/features/shared_widgets/custom_switch.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/navigation/navigation_service.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
@ -108,7 +107,12 @@ void showDeviceInterface(DeviceModel device, BuildContext context) {
case DeviceType.LightBulb:
navigateToInterface(LightInterface(light: device), context);
case DeviceType.ThreeGang:
navigateToInterface(ThreeGangInterface(gangSwitch: device), context);
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
ThreeGangInterface(gangSwitch: device)));
// navigateToInterface(ThreeGangInterface(gangSwitch: device), context);
break;
default:
}

View File

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
@ -11,41 +11,35 @@ class GangSwitch extends StatelessWidget {
const GangSwitch({
super.key,
required this.threeGangSwitch,
required this.control,
required this.value,
});
final DeviceModel threeGangSwitch;
final DeviceControlModel control;
final bool value;
@override
Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>(
return BlocBuilder<ThreeGangBloc, ThreeGangState>(
builder: (context, state) {
return InkWell(
overlayColor: MaterialStateProperty.all(Colors.transparent),
onTap: () {
var tempControl = DeviceControlModel(
deviceId: control.deviceId,
code: control.code!,
value: !control.value!);
DevicesCubit.getInstance().deviceControl(
tempControl,
control.deviceId!,
);
// var tempControl = DeviceControlModel(
// deviceId: control.deviceId, code: control.code!, value: !control.value!);
// DevicesCubit.getInstance().deviceControl(
// tempControl,
// control.deviceId!,
// );
},
child: Stack(
alignment:
!control.value! ? Alignment.topCenter : Alignment.bottomCenter,
alignment: value ? Alignment.topCenter : Alignment.bottomCenter,
children: [
Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(100.0)),
color: threeGangSwitch.status
.firstWhere((element) => element.code == control.code)
.value!
? ColorsManager.primaryColorWithOpacity
: ColorsManager.switchOffColor,
color:
value ? ColorsManager.primaryColorWithOpacity : ColorsManager.switchOffColor,
),
width: 60,
height: 115,
@ -54,22 +48,10 @@ class GangSwitch extends StatelessWidget {
padding: const EdgeInsets.all(5.0),
child: SizedBox.square(
dimension: 60,
child: state is GetDeviceStatusLoading &&
state.code == control.code ||
state is DeviceControlSuccess &&
state.code == control.code ||
state is DeviceControlLoading &&
state.code == control.code
? const SizedBox(
width: 10,
height: 10,
child: Center(child: CircularProgressIndicator()))
: SvgPicture.asset(
control.value!
? Assets.assetsIconsLightSwitchOn
: Assets.assetsIconsLightSwitchOff,
fit: BoxFit.fill,
),
child: SvgPicture.asset(
value ? Assets.assetsIconsLightSwitchOn : Assets.assetsIconsLightSwitchOff,
fit: BoxFit.fill,
),
),
),
],

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface_body.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_screen.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
@ -53,7 +53,7 @@ class ThreeGangInterface extends StatelessWidget {
right: Constants.defaultPadding,
bottom: Constants.bottomNavBarHeight,
),
child: ThreeGangInterfaceBody(
child: ThreeGangScreen(
device: gangSwitch,
),
),

View File

@ -1,328 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_gang/gang_switch.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class ThreeGangInterfaceBody extends StatelessWidget {
const ThreeGangInterfaceBody({
super.key,
required this.device,
});
final DeviceModel device;
@override
Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Expanded(child: SizedBox.shrink()),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
children: [
GangSwitch(
threeGangSwitch: device,
control: DeviceControlModel(
deviceId: device.uuid,
// code: 'switch_1',
code: device.status[0].code,
// value: true,
value: device.status[0].value,
),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Bedside Light",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
Column(
children: [
GangSwitch(
threeGangSwitch: device,
control: DeviceControlModel(
// deviceId: 'bfe10693d4fd263206ocq9',
// code: 'switch_2',
// value: true,
deviceId: device.uuid,
code: device.status[1].code,
value: device.status[1].value,
),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Ceiling Light",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
Column(
children: [
GangSwitch(
threeGangSwitch: device,
control: DeviceControlModel(
// deviceId: 'bfe10693d4fd263206ocq9',
// code: 'switch_3',
// value: true,
deviceId: device.uuid,
code: device.status[2].code,
value: device.status[2].value,
),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Spotlight",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
],
),
Expanded(
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
child: InkWell(
onTap: () {
DevicesCubit.getInstance().deviceControl(
DeviceControlModel(
deviceId: device.uuid,
code: 'switch_1',
value: true,
),
device.uuid!,
);
DevicesCubit.getInstance().deviceControl(
DeviceControlModel(
deviceId: device.uuid,
code: 'switch_2',
value: true,
),
device.uuid!,
);
DevicesCubit.getInstance().deviceControl(
DeviceControlModel(
deviceId: device.uuid,
code: 'switch_3',
value: true,
),
device.uuid!,
);
},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100),
),
child: Center(
child: BodySmall(
text: "On",
style: context.bodyMedium.copyWith(
color: ColorsManager
.primaryColorWithOpacity,
fontWeight: FontWeight.bold),
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "All On",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
const SizedBox(
width: 20,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
child: InkWell(
onTap: () {},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100),
),
child: Center(
child: Icon(
Icons.access_time,
color:
ColorsManager.primaryColorWithOpacity,
size: 25,
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "Timer",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
const SizedBox(
width: 20,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
child: InkWell(
onTap: () {
DevicesCubit.getInstance().deviceControl(
DeviceControlModel(
deviceId: device.uuid,
code: 'switch_1',
value: false,
),
device.uuid!,
);
DevicesCubit.getInstance().deviceControl(
DeviceControlModel(
deviceId: device.uuid,
code: 'switch_2',
value: false,
),
device.uuid!,
);
DevicesCubit.getInstance().deviceControl(
DeviceControlModel(
deviceId: device.uuid,
code: 'switch_3',
value: false,
),
device.uuid!,
);
},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100),
),
child: Center(
child: BodySmall(
text: "Off",
style: context.bodyMedium.copyWith(
color: ColorsManager
.primaryColorWithOpacity,
fontWeight: FontWeight.bold),
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "All Off",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
],
),
),
),
],
);
},
);
}
}

View File

@ -0,0 +1,341 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/three_gang_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_gang/gang_switch.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class ThreeGangScreen extends StatelessWidget {
const ThreeGangScreen({
super.key,
required this.device,
});
final DeviceModel device;
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => ThreeGangBloc(threeGangId: device.uuid ?? '')..add(InitialEvent()),
child: BlocBuilder<ThreeGangBloc, ThreeGangState>(
builder: (context, state) {
ThreeGangModel threeGangModel = ThreeGangModel(
firstSwitch: false,
secondSwitch: false,
thirdSwitch: false,
firstCountDown: 0,
secondCountDown: 0,
thirdCountDown: 0);
if (state is UpdateState) {
threeGangModel = state.threeGangModel;
}
return state is LoadingState
? const Center(
child:
DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Expanded(child: SizedBox.shrink()),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
children: [
GangSwitch(
threeGangSwitch: device,
value: threeGangModel.firstSwitch,
// control: DeviceControlModel(
// deviceId: device.uuid,
// // code: 'switch_1',
// code: device.status[0].code,
// // value: true,
// value: device.status[0].value,
// ),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Bedside Light",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
Column(
children: [
GangSwitch(
threeGangSwitch: device,
value: threeGangModel.secondSwitch,
// control: DeviceControlModel(
// // deviceId: 'bfe10693d4fd263206ocq9',
// // code: 'switch_2',
// // value: true,
// deviceId: device.uuid,
// code: device.status[1].code,
// value: device.status[1].value,
// ),
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Ceiling Light",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
Column(
children: [
GangSwitch(
threeGangSwitch: device,
value: threeGangModel.thirdSwitch,
),
const SizedBox(height: 20),
const SizedBox(
width: 70,
child: BodySmall(
text: "Spotlight",
fontColor: ColorsManager.textPrimaryColor,
textAlign: TextAlign.center,
),
),
],
),
],
),
Expanded(
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
child: GestureDetector(
onTap: () {
// DevicesCubit.getInstance().deviceControl(
// DeviceControlModel(
// deviceId: device.uuid,
// code: 'switch_1',
// value: true,
// ),
// device.uuid!,
// );
// DevicesCubit.getInstance().deviceControl(
// DeviceControlModel(
// deviceId: device.uuid,
// code: 'switch_2',
// value: true,
// ),
// device.uuid!,
// );
// DevicesCubit.getInstance().deviceControl(
// DeviceControlModel(
// deviceId: device.uuid,
// code: 'switch_3',
// value: true,
// ),
// device.uuid!,
// );
},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100),
),
child: Center(
child: BodySmall(
text: "On",
style: context.bodyMedium.copyWith(
color: ColorsManager.primaryColorWithOpacity,
fontWeight: FontWeight.bold),
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "All On",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
const SizedBox(
width: 20,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
child: GestureDetector(
onTap: () {},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100),
),
child: Center(
child: Icon(
Icons.access_time,
color: ColorsManager.primaryColorWithOpacity,
size: 25,
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "Timer",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
const SizedBox(
width: 20,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
child: GestureDetector(
onTap: () {
// DevicesCubit.getInstance().deviceControl(
// DeviceControlModel(
// deviceId: device.uuid,
// code: 'switch_1',
// value: false,
// ),
// device.uuid!,
// );
// DevicesCubit.getInstance().deviceControl(
// DeviceControlModel(
// deviceId: device.uuid,
// code: 'switch_2',
// value: false,
// ),
// device.uuid!,
// );
// DevicesCubit.getInstance().deviceControl(
// DeviceControlModel(
// deviceId: device.uuid,
// code: 'switch_3',
// value: false,
// ),
// device.uuid!,
// );
},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(100),
),
child: Center(
child: BodySmall(
text: "Off",
style: context.bodyMedium.copyWith(
color: ColorsManager.primaryColorWithOpacity,
fontWeight: FontWeight.bold),
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "All Off",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
],
),
),
),
],
);
},
),
);
}
}