mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
push ac function state selection
This commit is contained in:
@ -6,7 +6,7 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
||||||
import 'package:syncrow_web/services/locator.dart';
|
import 'package:syncrow_web/services/locator.dart';
|
||||||
import 'package:syncrow_web/utils/app_routes.dart';
|
import 'package:syncrow_web/utils/app_routes.dart';
|
||||||
|
148
lib/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart
Normal file
148
lib/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
||||||
|
|
||||||
|
part 'functions_bloc_event.dart';
|
||||||
|
part 'functions_bloc_state.dart';
|
||||||
|
|
||||||
|
class FunctionBloc extends Bloc<FunctionBlocEvent, FunctionBlocState> {
|
||||||
|
FunctionBloc() : super(const FunctionBlocState()) {
|
||||||
|
on<InitializeFunctions>(_onInitializeFunctions);
|
||||||
|
on<AddFunction>(_onAddFunction);
|
||||||
|
on<UpdateFunction>(_onUpdateFunctions);
|
||||||
|
on<UpdateFunctionValue>(_onUpdateFunctionValue);
|
||||||
|
on<UpdateFunctionCondition>(_onUpdateFunctionCondition);
|
||||||
|
on<RemoveFunction>(_onRemoveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onAddFunction(AddFunction event, Emitter<FunctionBlocState> emit) {
|
||||||
|
debugPrint('Adding function: ${event.functionData.function}');
|
||||||
|
final functions = List<DeviceFunctionData>.from(state.functions);
|
||||||
|
|
||||||
|
// Find existing function data
|
||||||
|
final existingIndex = functions.indexWhere(
|
||||||
|
(f) => f.function == event.functionData.function,
|
||||||
|
);
|
||||||
|
|
||||||
|
// If function exists, preserve its value and condition
|
||||||
|
if (existingIndex != -1) {
|
||||||
|
final existingData = functions[existingIndex];
|
||||||
|
functions[existingIndex] = DeviceFunctionData(
|
||||||
|
entityId: event.functionData.entityId,
|
||||||
|
function: event.functionData.function,
|
||||||
|
operationName: event.functionData.operationName,
|
||||||
|
value: existingData.value, // Preserve the existing value
|
||||||
|
condition: existingData.condition, // Preserve the existing condition
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
functions.add(event.functionData);
|
||||||
|
}
|
||||||
|
|
||||||
|
debugPrint('Functions after add: $functions');
|
||||||
|
emit(state.copyWith(
|
||||||
|
functions: functions,
|
||||||
|
selectedFunction: event.functionData.function,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onUpdateFunctions(
|
||||||
|
UpdateFunction event, Emitter<FunctionBlocState> emit) {
|
||||||
|
final functions = state.functions.map((data) {
|
||||||
|
return data.function == event.functionData.function
|
||||||
|
? event.functionData
|
||||||
|
: data;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
emit(state.copyWith(functions: functions));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onUpdateFunctionValue(
|
||||||
|
UpdateFunctionValue event,
|
||||||
|
Emitter<FunctionBlocState> emit,
|
||||||
|
) {
|
||||||
|
debugPrint('Updating function value: ${event.function} -> ${event.value}');
|
||||||
|
|
||||||
|
// Create a new list to ensure state immutability
|
||||||
|
final functions = List<DeviceFunctionData>.from(state.functions);
|
||||||
|
|
||||||
|
// Find the index of the function to update
|
||||||
|
final functionIndex = functions.indexWhere(
|
||||||
|
(data) => data.function == event.function,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (functionIndex != -1) {
|
||||||
|
// Update the existing function data while preserving other fields
|
||||||
|
final existingData = functions[functionIndex];
|
||||||
|
functions[functionIndex] = DeviceFunctionData(
|
||||||
|
entityId: existingData.entityId,
|
||||||
|
function: existingData.function,
|
||||||
|
operationName: existingData.operationName,
|
||||||
|
value: event.value,
|
||||||
|
condition: existingData.condition,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// If function doesn't exist, add it
|
||||||
|
functions.add(DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
function: event.function,
|
||||||
|
operationName: '',
|
||||||
|
value: event.value,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
debugPrint('Functions after update: $functions');
|
||||||
|
emit(state.copyWith(functions: functions));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onUpdateFunctionCondition(
|
||||||
|
UpdateFunctionCondition event,
|
||||||
|
Emitter<FunctionBlocState> emit,
|
||||||
|
) {
|
||||||
|
final functions = state.functions.map((data) {
|
||||||
|
if (data.function == event.function) {
|
||||||
|
return DeviceFunctionData(
|
||||||
|
entityId: data.entityId,
|
||||||
|
function: data.function,
|
||||||
|
operationName: data.operationName,
|
||||||
|
value: data.value,
|
||||||
|
condition: event.condition,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
emit(state.copyWith(functions: functions));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onRemoveFunction(
|
||||||
|
RemoveFunction event, Emitter<FunctionBlocState> emit) {
|
||||||
|
final functions = state.functions
|
||||||
|
.where((data) => data.function != event.functionCode)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
functions: functions,
|
||||||
|
selectedFunction: functions.isEmpty ? null : state.selectedFunction,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onInitializeFunctions(
|
||||||
|
InitializeFunctions event,
|
||||||
|
Emitter<FunctionBlocState> emit,
|
||||||
|
) {
|
||||||
|
emit(state.copyWith(functions: event.functions));
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceFunctionData? getFunction(String functionCode) {
|
||||||
|
return state.functions.firstWhere(
|
||||||
|
(data) => data.function == functionCode,
|
||||||
|
orElse: () => DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
function: functionCode,
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
part of 'functions_bloc_bloc.dart';
|
||||||
|
|
||||||
|
abstract class FunctionBlocEvent extends Equatable {
|
||||||
|
const FunctionBlocEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddFunction extends FunctionBlocEvent {
|
||||||
|
final DeviceFunctionData functionData;
|
||||||
|
|
||||||
|
const AddFunction({
|
||||||
|
required this.functionData,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [functionData];
|
||||||
|
}
|
||||||
|
|
||||||
|
class UpdateFunction extends FunctionBlocEvent {
|
||||||
|
final DeviceFunctionData functionData;
|
||||||
|
|
||||||
|
const UpdateFunction(this.functionData);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [functionData];
|
||||||
|
}
|
||||||
|
|
||||||
|
class UpdateFunctionValue extends FunctionBlocEvent {
|
||||||
|
final String function;
|
||||||
|
final dynamic value;
|
||||||
|
|
||||||
|
const UpdateFunctionValue({
|
||||||
|
required this.function,
|
||||||
|
required this.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [function, value];
|
||||||
|
}
|
||||||
|
|
||||||
|
class UpdateFunctionCondition extends FunctionBlocEvent {
|
||||||
|
final String function;
|
||||||
|
final String condition;
|
||||||
|
|
||||||
|
const UpdateFunctionCondition({
|
||||||
|
required this.function,
|
||||||
|
required this.condition,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [function, condition];
|
||||||
|
}
|
||||||
|
|
||||||
|
class RemoveFunction extends FunctionBlocEvent {
|
||||||
|
final String functionCode;
|
||||||
|
|
||||||
|
const RemoveFunction(this.functionCode);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [functionCode];
|
||||||
|
}
|
||||||
|
|
||||||
|
class InitializeFunctions extends FunctionBlocEvent {
|
||||||
|
final List<DeviceFunctionData> functions;
|
||||||
|
|
||||||
|
const InitializeFunctions(this.functions);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [functions];
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
part of 'functions_bloc_bloc.dart';
|
||||||
|
|
||||||
|
class FunctionBlocState extends Equatable {
|
||||||
|
final List<DeviceFunctionData> functions;
|
||||||
|
final String? selectedFunction;
|
||||||
|
|
||||||
|
const FunctionBlocState({
|
||||||
|
this.functions = const [],
|
||||||
|
this.selectedFunction,
|
||||||
|
});
|
||||||
|
|
||||||
|
FunctionBlocState copyWith({
|
||||||
|
List<DeviceFunctionData>? functions,
|
||||||
|
String? selectedFunction,
|
||||||
|
}) {
|
||||||
|
return FunctionBlocState(
|
||||||
|
functions: functions ?? this.functions,
|
||||||
|
selectedFunction: selectedFunction ?? this.selectedFunction,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [functions, selectedFunction];
|
||||||
|
}
|
@ -6,6 +6,8 @@ import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart';
|
|||||||
import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/bloc/functions_bloc/functions_bloc_bloc.dart';
|
||||||
|
|
||||||
class ACHelper {
|
class ACHelper {
|
||||||
static Future<Map<String, dynamic>?> showACFunctionsDialog(
|
static Future<Map<String, dynamic>?> showACFunctionsDialog(
|
||||||
@ -13,97 +15,122 @@ class ACHelper {
|
|||||||
List<DeviceFunction<dynamic>> functions,
|
List<DeviceFunction<dynamic>> functions,
|
||||||
) async {
|
) async {
|
||||||
List<ACFunction> acFunctions = functions.whereType<ACFunction>().toList();
|
List<ACFunction> acFunctions = functions.whereType<ACFunction>().toList();
|
||||||
final selectedFunctionNotifier = ValueNotifier<String?>(null);
|
|
||||||
final selectedValueNotifier = ValueNotifier<dynamic>(null);
|
// Initialize the FunctionBloc with existing functions
|
||||||
final selectedConditionNotifier = ValueNotifier<String?>('==');
|
final initialFunctions = acFunctions
|
||||||
final selectedConditionsNotifier =
|
.map((f) => DeviceFunctionData(
|
||||||
ValueNotifier<List<bool>>([false, true, false]);
|
entityId: '',
|
||||||
|
function: f.code,
|
||||||
|
operationName: f.operationName,
|
||||||
|
value: null,
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
|
||||||
return showDialog<Map<String, dynamic>?>(
|
return showDialog<Map<String, dynamic>?>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return ValueListenableBuilder<String?>(
|
return BlocProvider(
|
||||||
valueListenable: selectedFunctionNotifier,
|
create: (_) =>
|
||||||
builder: (context, selectedFunction, _) {
|
FunctionBloc()..add(InitializeFunctions(initialFunctions)),
|
||||||
return AlertDialog(
|
child: AlertDialog(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
content: Container(
|
content: BlocBuilder<FunctionBloc, FunctionBlocState>(
|
||||||
width: selectedFunction != null ? 600 : 360,
|
builder: (context, state) {
|
||||||
height: 450,
|
debugPrint(
|
||||||
decoration: BoxDecoration(
|
'Current state - Selected: ${state.selectedFunction}, Functions: ${state.functions}');
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
final selectedFunction = state.selectedFunction;
|
||||||
),
|
final selectedFunctionData = selectedFunction != null
|
||||||
padding: const EdgeInsets.only(top: 20),
|
? state.functions.firstWhere(
|
||||||
child: Column(
|
(f) => f.function == selectedFunction,
|
||||||
mainAxisSize: MainAxisSize.min,
|
orElse: () => DeviceFunctionData(
|
||||||
children: [
|
entityId: '',
|
||||||
const DialogHeader('AC Functions'),
|
function: selectedFunction,
|
||||||
Expanded(
|
operationName: '',
|
||||||
child: Row(
|
value: null,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
),
|
||||||
children: [
|
)
|
||||||
// Function list
|
: null;
|
||||||
SizedBox(
|
|
||||||
width: selectedFunction != null ? 320 : 360,
|
return Container(
|
||||||
child: _buildFunctionsList(
|
width: selectedFunction != null ? 600 : 360,
|
||||||
context,
|
height: 450,
|
||||||
acFunctions,
|
decoration: BoxDecoration(
|
||||||
selectedFunctionNotifier,
|
color: Colors.white,
|
||||||
),
|
borderRadius: BorderRadius.circular(20),
|
||||||
),
|
),
|
||||||
// Value selector
|
padding: const EdgeInsets.only(top: 20),
|
||||||
if (selectedFunction != null)
|
child: Column(
|
||||||
Expanded(
|
mainAxisSize: MainAxisSize.min,
|
||||||
child: _buildValueSelector(
|
children: [
|
||||||
|
const DialogHeader('AC Functions'),
|
||||||
|
Expanded(
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
// Function list
|
||||||
|
SizedBox(
|
||||||
|
width: selectedFunction != null ? 320 : 360,
|
||||||
|
child: _buildFunctionsList(
|
||||||
context,
|
context,
|
||||||
selectedFunction,
|
|
||||||
selectedValueNotifier,
|
|
||||||
selectedConditionNotifier,
|
|
||||||
selectedConditionsNotifier,
|
|
||||||
acFunctions,
|
acFunctions,
|
||||||
|
(functionCode) =>
|
||||||
|
context.read<FunctionBloc>().add(
|
||||||
|
AddFunction(
|
||||||
|
functionData: DeviceFunctionData(
|
||||||
|
entityId: '',
|
||||||
|
function: functionCode,
|
||||||
|
operationName: '',
|
||||||
|
value: null,
|
||||||
|
)),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
// Value selector
|
||||||
|
if (selectedFunction != null)
|
||||||
|
Expanded(
|
||||||
|
child: _buildValueSelector(
|
||||||
|
context,
|
||||||
|
selectedFunction,
|
||||||
|
selectedFunctionData,
|
||||||
|
(value) => context.read<FunctionBloc>().add(
|
||||||
|
UpdateFunctionValue(
|
||||||
|
function: selectedFunction,
|
||||||
|
value: value,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(condition) =>
|
||||||
|
context.read<FunctionBloc>().add(
|
||||||
|
UpdateFunctionCondition(
|
||||||
|
function: selectedFunction,
|
||||||
|
condition: condition,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
acFunctions,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
DialogFooter(
|
||||||
DialogFooter(
|
onCancel: () {
|
||||||
onCancel: () {
|
Navigator.pop(context);
|
||||||
selectedFunctionNotifier.dispose();
|
},
|
||||||
selectedValueNotifier.dispose();
|
onConfirm: selectedFunction != null &&
|
||||||
selectedConditionNotifier.dispose();
|
selectedFunctionData?.value != null
|
||||||
selectedConditionsNotifier.dispose();
|
? () {}
|
||||||
Navigator.pop(context);
|
: null,
|
||||||
},
|
isConfirmEnabled: selectedFunction != null,
|
||||||
onConfirm: selectedFunctionNotifier.value != null &&
|
),
|
||||||
selectedValueNotifier.value != null
|
],
|
||||||
? () {
|
),
|
||||||
selectedFunctionNotifier.dispose();
|
);
|
||||||
selectedValueNotifier.dispose();
|
},
|
||||||
selectedConditionNotifier.dispose();
|
),
|
||||||
selectedConditionsNotifier.dispose();
|
),
|
||||||
Navigator.pop(context, {
|
|
||||||
'function': selectedFunctionNotifier.value,
|
|
||||||
'value': selectedValueNotifier.value,
|
|
||||||
'condition':
|
|
||||||
selectedConditionNotifier.value ?? "==",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
isConfirmEnabled: selectedFunction != null,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
).then((value) {
|
).then((value) {
|
||||||
selectedFunctionNotifier.dispose();
|
|
||||||
selectedValueNotifier.dispose();
|
|
||||||
selectedConditionNotifier.dispose();
|
|
||||||
selectedConditionsNotifier.dispose();
|
|
||||||
return value;
|
return value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -112,7 +139,7 @@ class ACHelper {
|
|||||||
static Widget _buildFunctionsList(
|
static Widget _buildFunctionsList(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
List<ACFunction> acFunctions,
|
List<ACFunction> acFunctions,
|
||||||
ValueNotifier<String?> selectedFunctionNotifier,
|
Function(String) onFunctionSelected,
|
||||||
) {
|
) {
|
||||||
return ListView.separated(
|
return ListView.separated(
|
||||||
shrinkWrap: false,
|
shrinkWrap: false,
|
||||||
@ -146,7 +173,7 @@ class ACHelper {
|
|||||||
size: 16,
|
size: 16,
|
||||||
color: ColorsManager.textGray,
|
color: ColorsManager.textGray,
|
||||||
),
|
),
|
||||||
onTap: () => selectedFunctionNotifier.value = function.code,
|
onTap: () => onFunctionSelected(function.code),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -156,60 +183,57 @@ class ACHelper {
|
|||||||
static Widget _buildValueSelector(
|
static Widget _buildValueSelector(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
String selectedFunction,
|
String selectedFunction,
|
||||||
ValueNotifier<dynamic> selectedValueNotifier,
|
DeviceFunctionData? selectedFunctionData,
|
||||||
ValueNotifier<String?> selectedConditionNotifier,
|
Function(dynamic) onValueChanged,
|
||||||
ValueNotifier<List<bool>> selectedConditionsNotifier,
|
Function(String) onConditionChanged,
|
||||||
List<ACFunction> acFunctions,
|
List<ACFunction> acFunctions,
|
||||||
) {
|
) {
|
||||||
// Handle temperature functions
|
|
||||||
if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') {
|
if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') {
|
||||||
// Initialize with 20°C (200 in internal representation)
|
final initialValue = selectedFunctionData?.value ?? 200;
|
||||||
if (selectedValueNotifier.value == null ||
|
|
||||||
selectedValueNotifier.value is! int) {
|
|
||||||
selectedValueNotifier.value = 200;
|
|
||||||
}
|
|
||||||
return _buildTemperatureSelector(
|
return _buildTemperatureSelector(
|
||||||
context,
|
context,
|
||||||
selectedValueNotifier,
|
initialValue,
|
||||||
selectedConditionNotifier,
|
selectedFunctionData?.condition,
|
||||||
selectedConditionsNotifier,
|
onValueChanged,
|
||||||
|
onConditionChanged,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle other functions
|
|
||||||
final selectedFn =
|
final selectedFn =
|
||||||
acFunctions.firstWhere((f) => f.code == selectedFunction);
|
acFunctions.firstWhere((f) => f.code == selectedFunction);
|
||||||
final values = selectedFn.getOperationalValues();
|
final values = selectedFn.getOperationalValues();
|
||||||
|
|
||||||
// Don't set any default value for non-temperature functions
|
|
||||||
return _buildOperationalValuesList(
|
return _buildOperationalValuesList(
|
||||||
context,
|
context,
|
||||||
values,
|
values,
|
||||||
selectedValueNotifier,
|
selectedFunctionData?.value,
|
||||||
|
onValueChanged,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build temperature selector for AC functions dialog
|
/// Build temperature selector for AC functions dialog
|
||||||
static Widget _buildTemperatureSelector(
|
static Widget _buildTemperatureSelector(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
ValueNotifier<dynamic> selectedValueNotifier,
|
dynamic initialValue,
|
||||||
ValueNotifier<String?> selectedConditionNotifier,
|
String? currentCondition,
|
||||||
ValueNotifier<List<bool>> selectedConditionsNotifier,
|
Function(dynamic) onValueChanged,
|
||||||
|
Function(String) onConditionChanged,
|
||||||
) {
|
) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
_buildConditionToggle(
|
_buildConditionToggle(
|
||||||
context,
|
context,
|
||||||
selectedConditionNotifier,
|
currentCondition,
|
||||||
selectedConditionsNotifier,
|
onConditionChanged,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
_buildTemperatureDisplay(context, selectedValueNotifier),
|
_buildTemperatureDisplay(context, initialValue),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
_buildTemperatureSlider(
|
_buildTemperatureSlider(
|
||||||
context,
|
context,
|
||||||
selectedValueNotifier,
|
initialValue,
|
||||||
|
onValueChanged,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -218,79 +242,61 @@ class ACHelper {
|
|||||||
/// Build condition toggle for AC functions dialog
|
/// Build condition toggle for AC functions dialog
|
||||||
static Widget _buildConditionToggle(
|
static Widget _buildConditionToggle(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
ValueNotifier<String?> selectedConditionNotifier,
|
String? currentCondition,
|
||||||
ValueNotifier<List<bool>> selectedConditionsNotifier,
|
Function(String) onConditionChanged,
|
||||||
) {
|
) {
|
||||||
return ValueListenableBuilder<List<bool>>(
|
final conditions = ["<", "==", ">"];
|
||||||
valueListenable: selectedConditionsNotifier,
|
|
||||||
builder: (context, selectedConditions, _) {
|
return ToggleButtons(
|
||||||
return ToggleButtons(
|
onPressed: (int index) {
|
||||||
onPressed: (int index) {
|
onConditionChanged(conditions[index]);
|
||||||
final newConditions = [false, false, false];
|
|
||||||
newConditions[index] = true;
|
|
||||||
selectedConditionsNotifier.value = newConditions;
|
|
||||||
selectedConditionNotifier.value = index == 0
|
|
||||||
? "<"
|
|
||||||
: index == 1
|
|
||||||
? "=="
|
|
||||||
: ">";
|
|
||||||
},
|
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
||||||
selectedBorderColor: ColorsManager.primaryColorWithOpacity,
|
|
||||||
selectedColor: Colors.white,
|
|
||||||
fillColor: ColorsManager.primaryColorWithOpacity,
|
|
||||||
color: ColorsManager.primaryColorWithOpacity,
|
|
||||||
constraints: const BoxConstraints(
|
|
||||||
minHeight: 40.0,
|
|
||||||
minWidth: 40.0,
|
|
||||||
),
|
|
||||||
isSelected: selectedConditions,
|
|
||||||
children: const [Text("<"), Text("="), Text(">")],
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||||
|
selectedBorderColor: ColorsManager.primaryColorWithOpacity,
|
||||||
|
selectedColor: Colors.white,
|
||||||
|
fillColor: ColorsManager.primaryColorWithOpacity,
|
||||||
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
minHeight: 40.0,
|
||||||
|
minWidth: 40.0,
|
||||||
|
),
|
||||||
|
isSelected:
|
||||||
|
conditions.map((c) => c == (currentCondition ?? "==")).toList(),
|
||||||
|
children: conditions.map((c) => Text(c)).toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build temperature display for AC functions dialog
|
/// Build temperature display for AC functions dialog
|
||||||
static Widget _buildTemperatureDisplay(
|
static Widget _buildTemperatureDisplay(
|
||||||
BuildContext context, ValueNotifier<dynamic> selectedValueNotifier) {
|
BuildContext context, dynamic initialValue) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: ColorsManager.primaryColorWithOpacity.withOpacity(0.1),
|
color: ColorsManager.primaryColorWithOpacity.withOpacity(0.1),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
child: ValueListenableBuilder(
|
child: Text(
|
||||||
valueListenable: selectedValueNotifier,
|
'${(initialValue ?? 200) / 10}°C',
|
||||||
builder: (context, selectedValue, child) {
|
style: context.textTheme.headlineMedium!.copyWith(
|
||||||
return Text(
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
'${(selectedValue ?? 200) / 10}°C',
|
),
|
||||||
style: context.textTheme.headlineMedium!.copyWith(
|
|
||||||
color: ColorsManager.primaryColorWithOpacity,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Widget _buildTemperatureSlider(
|
static Widget _buildTemperatureSlider(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
ValueNotifier<dynamic> selectedValueNotifier,
|
dynamic initialValue,
|
||||||
|
Function(dynamic) onValueChanged,
|
||||||
) {
|
) {
|
||||||
return ValueListenableBuilder(
|
return Slider(
|
||||||
valueListenable: selectedValueNotifier,
|
value: initialValue is int ? initialValue.toDouble() : 200.0,
|
||||||
builder: (context, selectedValue, child) {
|
min: 160,
|
||||||
final currentValue =
|
max: 300,
|
||||||
selectedValue is int ? selectedValue.toDouble() : 200.0;
|
divisions: 14,
|
||||||
return Slider(
|
label: '${((initialValue ?? 200) / 10).toInt()}°C',
|
||||||
value: currentValue,
|
onChanged: (value) {
|
||||||
min: 160,
|
onValueChanged(value.toInt());
|
||||||
max: 300,
|
|
||||||
divisions: 14,
|
|
||||||
label: '${(currentValue / 10).toInt()}°C',
|
|
||||||
onChanged: (value) => selectedValueNotifier.value = value.toInt(),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -298,40 +304,44 @@ class ACHelper {
|
|||||||
static Widget _buildOperationalValuesList(
|
static Widget _buildOperationalValuesList(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
List<dynamic> values,
|
List<dynamic> values,
|
||||||
ValueNotifier<dynamic> selectedValueNotifier,
|
dynamic selectedValue,
|
||||||
|
Function(dynamic) onValueChanged,
|
||||||
) {
|
) {
|
||||||
return ValueListenableBuilder<dynamic>(
|
return ListView.builder(
|
||||||
valueListenable: selectedValueNotifier,
|
shrinkWrap: false,
|
||||||
builder: (context, selectedValue, _) {
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
return ListView.builder(
|
itemCount: values.length,
|
||||||
shrinkWrap: false,
|
itemBuilder: (context, index) {
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
final value = values[index];
|
||||||
itemCount: values.length,
|
final isSelected = selectedValue == value.value;
|
||||||
itemBuilder: (context, index) {
|
return ListTile(
|
||||||
final value = values[index];
|
leading: SvgPicture.asset(
|
||||||
return ListTile(
|
value.icon,
|
||||||
leading: SvgPicture.asset(
|
width: 24,
|
||||||
value.icon,
|
height: 24,
|
||||||
width: 24,
|
placeholderBuilder: (BuildContext context) => Container(
|
||||||
height: 24,
|
width: 24,
|
||||||
placeholderBuilder: (BuildContext context) => Container(
|
height: 24,
|
||||||
width: 24,
|
color: Colors.transparent,
|
||||||
height: 24,
|
),
|
||||||
color: Colors.transparent,
|
),
|
||||||
),
|
title: Text(
|
||||||
),
|
value.description,
|
||||||
title: Text(
|
style: context.textTheme.bodyMedium,
|
||||||
value.description,
|
),
|
||||||
style: context.textTheme.bodyMedium,
|
trailing: Icon(
|
||||||
),
|
isSelected
|
||||||
trailing: Radio<dynamic>(
|
? Icons.radio_button_checked
|
||||||
value: value.value,
|
: Icons.radio_button_unchecked,
|
||||||
groupValue: selectedValue,
|
size: 24,
|
||||||
onChanged: (_) => selectedValueNotifier.value = value.value,
|
color: isSelected
|
||||||
activeColor: ColorsManager.primaryColorWithOpacity,
|
? ColorsManager.primaryColorWithOpacity
|
||||||
),
|
: ColorsManager.textGray,
|
||||||
onTap: () => selectedValueNotifier.value = value.value,
|
),
|
||||||
);
|
onTap: () {
|
||||||
|
if (!isSelected) {
|
||||||
|
onValueChanged(value.value);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -58,4 +58,29 @@ class DeviceFunctionData {
|
|||||||
valueDescription: json['valueDescription'],
|
valueDescription: json['valueDescription'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other is DeviceFunctionData &&
|
||||||
|
other.entityId == entityId &&
|
||||||
|
other.actionExecutor == actionExecutor &&
|
||||||
|
other.function == function &&
|
||||||
|
other.operationName == operationName &&
|
||||||
|
other.value == value &&
|
||||||
|
other.condition == condition &&
|
||||||
|
other.valueDescription == valueDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return entityId.hashCode ^
|
||||||
|
actionExecutor.hashCode ^
|
||||||
|
function.hashCode ^
|
||||||
|
operationName.hashCode ^
|
||||||
|
value.hashCode ^
|
||||||
|
condition.hashCode ^
|
||||||
|
valueDescription.hashCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/routine_devices.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/routine_devices.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/routines_title_widget.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/routines_title_widget.dart';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/helper/dialog_helper/device_dialog_helper.dart';
|
import 'package:syncrow_web/pages/routiens/helper/dialog_helper/device_dialog_helper.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
||||||
|
|
||||||
class RoutineDevices extends StatelessWidget {
|
class RoutineDevices extends StatelessWidget {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/helper/dialog_helper/device_dialog_helper.dart';
|
import 'package:syncrow_web/pages/routiens/helper/dialog_helper/device_dialog_helper.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user