mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-26 19:34:54 +00:00
@ -40,8 +40,7 @@ class ThreeGangGlassSwitchBloc
|
||||
) async {
|
||||
emit(ThreeGangGlassSwitchLoading());
|
||||
try {
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
_listenToChanges(event.deviceId, emit);
|
||||
deviceStatus =
|
||||
ThreeGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
||||
@ -65,7 +64,7 @@ class ThreeGangGlassSwitchBloc
|
||||
|
||||
final statusList = <Status>[];
|
||||
if (data['status'] != null) {
|
||||
for (final element in data['status']) {
|
||||
for (var element in data['status']) {
|
||||
statusList.add(
|
||||
Status(
|
||||
code: element['code'].toString(),
|
||||
@ -75,8 +74,7 @@ class ThreeGangGlassSwitchBloc
|
||||
}
|
||||
}
|
||||
if (statusList.isNotEmpty) {
|
||||
final newStatus =
|
||||
ThreeGangGlassStatusModel.fromJson(deviceId, statusList);
|
||||
final newStatus = ThreeGangGlassStatusModel.fromJson(deviceId, statusList);
|
||||
if (newStatus != deviceStatus) {
|
||||
deviceStatus = newStatus;
|
||||
if (!isClosed) {
|
||||
@ -144,10 +142,9 @@ class ThreeGangGlassSwitchBloc
|
||||
) async {
|
||||
emit(ThreeGangGlassSwitchLoading());
|
||||
try {
|
||||
final status =
|
||||
await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
||||
deviceStatus = ThreeGangGlassStatusModel.fromJson(
|
||||
event.deviceIds.first, status.status);
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
||||
deviceStatus =
|
||||
ThreeGangGlassStatusModel.fromJson(event.deviceIds.first, status.status);
|
||||
emit(ThreeGangGlassSwitchBatchStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
emit(ThreeGangGlassSwitchError(e.toString()));
|
||||
|
||||
@ -27,7 +27,7 @@ class ThreeGangGlassStatusModel {
|
||||
late bool switch3;
|
||||
late int countDown3;
|
||||
|
||||
for (final status in jsonList) {
|
||||
for (var status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'switch_1':
|
||||
switch1 = status.value ?? false;
|
||||
|
||||
@ -9,19 +9,16 @@ import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/factorie
|
||||
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/models/three_gang_glass_switch.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
class ThreeGangGlassSwitchBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
final List<String> deviceIds;
|
||||
|
||||
const ThreeGangGlassSwitchBatchControlView(
|
||||
{required this.deviceIds, super.key});
|
||||
const ThreeGangGlassSwitchBatchControlView({required this.deviceIds, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) =>
|
||||
ThreeGangGlassSwitchBlocFactory.create(deviceId: deviceIds.first)
|
||||
..add(ThreeGangGlassSwitchFetchBatchStatusEvent(deviceIds)),
|
||||
create: (context) => ThreeGangGlassSwitchBlocFactory.create(deviceId: deviceIds.first)
|
||||
..add(ThreeGangGlassSwitchFetchBatchStatusEvent(deviceIds)),
|
||||
child: BlocBuilder<ThreeGangGlassSwitchBloc, ThreeGangGlassSwitchState>(
|
||||
builder: (context, state) {
|
||||
if (state is ThreeGangGlassSwitchLoading) {
|
||||
@ -38,8 +35,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, ThreeGangGlassStatusModel status) {
|
||||
Widget _buildStatusControls(BuildContext context, ThreeGangGlassStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
@ -62,7 +58,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
|
||||
value: status.switch1,
|
||||
code: 'switch_1',
|
||||
deviceId: deviceIds.first,
|
||||
label: 'Wall Light',
|
||||
label: "Wall Light",
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchBatchControl(
|
||||
@ -77,7 +73,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
|
||||
value: status.switch2,
|
||||
code: 'switch_2',
|
||||
deviceId: deviceIds.first,
|
||||
label: 'Ceiling Light',
|
||||
label: "Ceiling Light",
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchBatchControl(
|
||||
@ -92,7 +88,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
|
||||
value: status.switch3,
|
||||
code: 'switch_3',
|
||||
deviceId: deviceIds.first,
|
||||
label: 'SpotLight',
|
||||
label: "SpotLight",
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchBatchControl(
|
||||
|
||||
@ -3,12 +3,12 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/bloc/three_gang_glass_switch_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/factories/three_gang_glass_switch_bloc_factory.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/models/three_gang_glass_switch.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class ThreeGangGlassSwitchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
import '../models/three_gang_glass_switch.dart';
|
||||
|
||||
class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
final String deviceId;
|
||||
|
||||
const ThreeGangGlassSwitchControlView({required this.deviceId, super.key});
|
||||
@ -17,8 +17,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) =>
|
||||
ThreeGangGlassSwitchBlocFactory.create(deviceId: deviceId)
|
||||
..add(ThreeGangGlassSwitchFetchDeviceEvent(deviceId)),
|
||||
ThreeGangGlassSwitchBlocFactory.create(deviceId: deviceId)..add(ThreeGangGlassSwitchFetchDeviceEvent(deviceId)),
|
||||
child: BlocBuilder<ThreeGangGlassSwitchBloc, ThreeGangGlassSwitchState>(
|
||||
builder: (context, state) {
|
||||
if (state is ThreeGangGlassSwitchLoading) {
|
||||
@ -35,8 +34,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, ThreeGangGlassStatusModel status) {
|
||||
Widget _buildStatusControls(BuildContext context, ThreeGangGlassStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
@ -59,7 +57,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
|
||||
value: status.switch1,
|
||||
code: 'switch_1',
|
||||
deviceId: deviceId,
|
||||
label: 'Wall Light',
|
||||
label: "Wall Light",
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchControl(
|
||||
@ -74,7 +72,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
|
||||
value: status.switch2,
|
||||
code: 'switch_2',
|
||||
deviceId: deviceId,
|
||||
label: 'Ceiling Light',
|
||||
label: "Ceiling Light",
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchControl(
|
||||
@ -89,7 +87,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
|
||||
value: status.switch3,
|
||||
code: 'switch_3',
|
||||
deviceId: deviceId,
|
||||
label: 'SpotLight',
|
||||
label: "SpotLight",
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchControl(
|
||||
|
||||
Reference in New Issue
Block a user