mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
finished AC
This commit is contained in:
@ -6,8 +6,9 @@ import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/view/control_list/ac_mode.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/view/control_list/ac_toggle.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/view/control_list/current_temp.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/view/control_list/fan_speed.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
||||
@ -20,13 +21,58 @@ class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
return BlocProvider(
|
||||
create: (context) => AcBloc()..add(AcFetchDeviceStatus(device.uuid!)),
|
||||
create: (context) => AcBloc(deviceId: device.uuid!)
|
||||
..add(AcFetchDeviceStatus(device.uuid!)),
|
||||
child: BlocBuilder<AcBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
if (state is AcsLoadingState) {
|
||||
if (state is ACStatusLoaded) {
|
||||
return GridView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: isLarge
|
||||
? 3
|
||||
: isMedium
|
||||
? 2
|
||||
: 1,
|
||||
mainAxisExtent: 133,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
children: [
|
||||
AcToggle(
|
||||
value: state.status.acSwitch,
|
||||
code: 'switch',
|
||||
deviceId: device.uuid!,
|
||||
),
|
||||
CurrentTemp(
|
||||
currentTemp: state.status.currentTemp,
|
||||
tempSet: state.status.tempSet,
|
||||
code: 'temp_set',
|
||||
deviceId: device.uuid!,
|
||||
),
|
||||
AcMode(
|
||||
value: state.status.acMode,
|
||||
code: 'mode',
|
||||
deviceId: device.uuid!,
|
||||
),
|
||||
FanSpeedControl(
|
||||
value: state.status.acFanSpeed,
|
||||
code: 'level',
|
||||
deviceId: device.uuid!,
|
||||
),
|
||||
AcToggle(
|
||||
value: state.status.childLock,
|
||||
code: 'child_lock',
|
||||
deviceId: device.uuid!,
|
||||
description: 'Child Lock',
|
||||
icon: Assets.childLock,
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (state is AcsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is ACStatusLoaded) {
|
||||
return _buildStatusControls(state.status, isLarge, isMedium);
|
||||
} else {
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
}
|
||||
@ -34,40 +80,4 @@ class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(AcStatusModel statuses, bool isLarge, bool isMedium) {
|
||||
return GridView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: isLarge
|
||||
? 3
|
||||
: isMedium
|
||||
? 2
|
||||
: 1,
|
||||
mainAxisExtent: 133,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
children: [
|
||||
AcToggle(
|
||||
value: statuses.acSwitch,
|
||||
code: 'switch',
|
||||
deviceId: statuses.uuid,
|
||||
),
|
||||
AcMode(
|
||||
value: statuses.acMode,
|
||||
code: 'mode',
|
||||
deviceId: statuses.uuid,
|
||||
),
|
||||
CurrentTemp(
|
||||
currentTemp: statuses.currentTemp,
|
||||
tempSet: statuses.tempSet,
|
||||
code: 'temp_set',
|
||||
deviceId: statuses.uuid,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,6 @@ class AcMode extends StatelessWidget {
|
||||
final String code;
|
||||
final String deviceId;
|
||||
|
||||
void _onModeSelected(BuildContext context, TempModes mode) {
|
||||
context.read<AcBloc>().add(
|
||||
ChangeAcMode(tempModes: mode, deviceId: deviceId),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@ -54,7 +48,13 @@ class AcMode extends StatelessWidget {
|
||||
return Flexible(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
_onModeSelected(context, mode);
|
||||
context.read<AcBloc>().add(
|
||||
AcControl(
|
||||
deviceId: deviceId,
|
||||
code: code,
|
||||
value: mode.name,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: 50,
|
||||
|
@ -53,7 +53,7 @@ class _CurrentTempState extends State<CurrentTemp> {
|
||||
AcControl(
|
||||
deviceId: widget.deviceId,
|
||||
code: widget.code,
|
||||
value: newValue * 10,
|
||||
value: (newValue * 10).toInt(),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
@ -0,0 +1,91 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
|
||||
|
||||
class FanSpeedControl extends StatelessWidget {
|
||||
const FanSpeedControl({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.code,
|
||||
required this.deviceId,
|
||||
});
|
||||
|
||||
final FanSpeeds value;
|
||||
final String code;
|
||||
final String deviceId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: ColorsManager.greyColor.withOpacity(0.2),
|
||||
border: Border.all(color: ColorsManager.boxDivider),
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
children: [
|
||||
Wrap(
|
||||
runSpacing: 8,
|
||||
spacing: 8,
|
||||
children: [
|
||||
_buildIconContainer(context, FanSpeeds.auto, Assets.acFanAuto,
|
||||
value == FanSpeeds.auto),
|
||||
_buildIconContainer(context, FanSpeeds.low, Assets.acFanLow,
|
||||
value == FanSpeeds.low),
|
||||
],
|
||||
),
|
||||
Wrap(
|
||||
runSpacing: 8,
|
||||
spacing: 8,
|
||||
children: [
|
||||
_buildIconContainer(context, FanSpeeds.middle, Assets.acFanMiddle,
|
||||
value == FanSpeeds.middle),
|
||||
_buildIconContainer(context, FanSpeeds.high, Assets.acFanHigh,
|
||||
value == FanSpeeds.high),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconContainer(BuildContext context, FanSpeeds speed,
|
||||
String assetPath, bool isSelected) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
context.read<AcBloc>().add(
|
||||
AcControl(
|
||||
deviceId: deviceId,
|
||||
code: code,
|
||||
value: speed.name,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: ColorsManager.whiteColors,
|
||||
border: Border.all(
|
||||
color: isSelected ? Colors.blue : Colors.transparent,
|
||||
width: 2.0,
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: ClipOval(
|
||||
child: SvgPicture.asset(
|
||||
assetPath,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user