mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-27 03:27:55 +00:00
setting
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:firebase_database/firebase_database.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/one_touch_bloc/one_touch_state.dart';
|
||||
@@ -21,9 +22,9 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
OneTouchModel deviceStatus = OneTouchModel(
|
||||
firstSwitch: false,
|
||||
firstCountDown: 0,
|
||||
light_mode: '',
|
||||
light_mode: lightStatus.off,
|
||||
relay: status.off,
|
||||
relay_status_1: '');
|
||||
relay_status_1: status.off);
|
||||
Timer? _timer;
|
||||
|
||||
bool oneTouchGroup = false;
|
||||
@@ -582,19 +583,22 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
|
||||
void _changeStatus(
|
||||
ChangeStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||
// emit(LoadingNewState(oneTouchModel: deviceStatus));
|
||||
emit(LoadingInitialState());
|
||||
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||
|
||||
try {
|
||||
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||
await _handleDeviceControl(event.deviceId);
|
||||
await _handleDeviceControl(event.deviceId, event.context);
|
||||
add(InitialEvent(groupScreen: oneTouchGroup));
|
||||
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||
} catch (error) {
|
||||
print('Error controlling device: $error');
|
||||
add(InitialEvent(groupScreen: oneTouchGroup));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleDeviceControl(String deviceId) async {
|
||||
Future<void> _handleDeviceControl(
|
||||
String deviceId, BuildContext context) async {
|
||||
final Map<String, Map<String, String>> controlMap = {
|
||||
"relay_status": {
|
||||
'Power On': 'power_on',
|
||||
@@ -619,6 +623,10 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
DeviceControlModel(
|
||||
deviceId: oneTouchId, code: optionSelected, value: selectedControl),
|
||||
oneTouchId,
|
||||
).then(
|
||||
(value) {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
print('Invalid statusSelected or optionSelected');
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
abstract class OneTouchEvent extends Equatable {
|
||||
const OneTouchEvent();
|
||||
@@ -142,5 +143,6 @@ class ChangeFirstWizardSwitchStatusEvent extends OneTouchEvent {
|
||||
|
||||
class ChangeStatusEvent extends OneTouchEvent {
|
||||
final String deviceId;
|
||||
const ChangeStatusEvent({this.deviceId = ''});
|
||||
final BuildContext context;
|
||||
const ChangeStatusEvent({this.deviceId = '',required this.context});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user