mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-26 09:04:55 +00:00
Added tab to run to if container
This commit is contained in:
@ -11,6 +11,9 @@ part 'routine_state.dart';
|
|||||||
const spaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
const spaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
||||||
|
|
||||||
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||||
|
bool isAutomation = false;
|
||||||
|
bool isTabToRun = false;
|
||||||
|
|
||||||
RoutineBloc() : super(const RoutineState()) {
|
RoutineBloc() : super(const RoutineState()) {
|
||||||
on<AddToIfContainer>(_onAddToIfContainer);
|
on<AddToIfContainer>(_onAddToIfContainer);
|
||||||
on<AddToThenContainer>(_onAddToThenContainer);
|
on<AddToThenContainer>(_onAddToThenContainer);
|
||||||
@ -23,17 +26,15 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
void _onAddToIfContainer(AddToIfContainer event, Emitter<RoutineState> emit) {
|
void _onAddToIfContainer(AddToIfContainer event, Emitter<RoutineState> emit) {
|
||||||
// if (!_isDuplicate(state.ifItems, event.item)) {
|
// if (!_isDuplicate(state.ifItems, event.item)) {
|
||||||
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems)
|
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems)..add(event.item);
|
||||||
..add(event.item);
|
isTabToRun = event.isTabToRun;
|
||||||
emit(state.copyWith(ifItems: updatedIfItems));
|
emit(state.copyWith(ifItems: updatedIfItems));
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onAddToThenContainer(
|
void _onAddToThenContainer(AddToThenContainer event, Emitter<RoutineState> emit) {
|
||||||
AddToThenContainer event, Emitter<RoutineState> emit) {
|
|
||||||
// if (!_isDuplicate(state.thenItems, event.item)) {
|
// if (!_isDuplicate(state.thenItems, event.item)) {
|
||||||
final updatedThenItems = List<Map<String, dynamic>>.from(state.thenItems)
|
final updatedThenItems = List<Map<String, dynamic>>.from(state.thenItems)..add(event.item);
|
||||||
..add(event.item);
|
|
||||||
emit(state.copyWith(thenItems: updatedThenItems));
|
emit(state.copyWith(thenItems: updatedThenItems));
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
@ -47,9 +48,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
void _onRemoveFunction(RemoveFunction event, Emitter<RoutineState> emit) {
|
void _onRemoveFunction(RemoveFunction event, Emitter<RoutineState> emit) {
|
||||||
final functions = List<DeviceFunctionData>.from(state.selectedFunctions)
|
final functions = List<DeviceFunctionData>.from(state.selectedFunctions)
|
||||||
..removeWhere((f) =>
|
..removeWhere(
|
||||||
f.functionCode == event.function.functionCode &&
|
(f) => f.functionCode == event.function.functionCode && f.value == event.function.value);
|
||||||
f.value == event.function.value);
|
|
||||||
emit(state.copyWith(selectedFunctions: functions));
|
emit(state.copyWith(selectedFunctions: functions));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +64,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
// item['title'] == newItem['title']);
|
// item['title'] == newItem['title']);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Future<void> _onLoadScenes(
|
Future<void> _onLoadScenes(LoadScenes event, Emitter<RoutineState> emit) async {
|
||||||
LoadScenes event, Emitter<RoutineState> emit) async {
|
|
||||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -82,8 +81,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadAutomation(
|
Future<void> _onLoadAutomation(LoadAutomation event, Emitter<RoutineState> emit) async {
|
||||||
LoadAutomation event, Emitter<RoutineState> emit) async {
|
|
||||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -9,11 +9,12 @@ abstract class RoutineEvent extends Equatable {
|
|||||||
|
|
||||||
class AddToIfContainer extends RoutineEvent {
|
class AddToIfContainer extends RoutineEvent {
|
||||||
final Map<String, dynamic> item;
|
final Map<String, dynamic> item;
|
||||||
|
final bool isTabToRun;
|
||||||
|
|
||||||
const AddToIfContainer(this.item);
|
const AddToIfContainer(this.item, this.isTabToRun);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [item];
|
List<Object> get props => [item, isTabToRun];
|
||||||
}
|
}
|
||||||
|
|
||||||
class AddToThenContainer extends RoutineEvent {
|
class AddToThenContainer extends RoutineEvent {
|
||||||
|
|||||||
@ -22,9 +22,8 @@ class DraggableCard extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final deviceFunctions = state.selectedFunctions
|
final deviceFunctions =
|
||||||
.where((f) => f.entityId == deviceData['deviceId'])
|
state.selectedFunctions.where((f) => f.entityId == deviceData['deviceId']).toList();
|
||||||
.toList();
|
|
||||||
|
|
||||||
return Draggable<Map<String, dynamic>>(
|
return Draggable<Map<String, dynamic>>(
|
||||||
data: deviceData,
|
data: deviceData,
|
||||||
@ -39,8 +38,7 @@ class DraggableCard extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildCardContent(
|
Widget _buildCardContent(BuildContext context, List<DeviceFunctionData> deviceFunctions) {
|
||||||
BuildContext context, List<DeviceFunctionData> deviceFunctions) {
|
|
||||||
return Card(
|
return Card(
|
||||||
color: ColorsManager.whiteColors,
|
color: ColorsManager.whiteColors,
|
||||||
child: Container(
|
child: Container(
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_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';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
class IfContainer extends StatelessWidget {
|
class IfContainer extends StatelessWidget {
|
||||||
const IfContainer({super.key});
|
const IfContainer({super.key});
|
||||||
@ -19,35 +20,49 @@ class IfContainer extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Text('IF',
|
const Text('IF', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
style:
|
|
||||||
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Wrap(
|
if (context.read<RoutineBloc>().isTabToRun)
|
||||||
spacing: 8,
|
const Row(
|
||||||
runSpacing: 8,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: state.ifItems
|
children: [
|
||||||
.map((item) => DraggableCard(
|
DraggableCard(
|
||||||
key: Key(item['key']!),
|
imagePath: Assets.tabToRun,
|
||||||
imagePath: item['imagePath']!,
|
title: 'Tab to run',
|
||||||
title: item['title']!,
|
deviceData: {},
|
||||||
deviceData: item,
|
),
|
||||||
))
|
],
|
||||||
.toList(),
|
),
|
||||||
),
|
if (!context.read<RoutineBloc>().isTabToRun)
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: state.ifItems
|
||||||
|
.map((item) => DraggableCard(
|
||||||
|
// key: Key(item['key']!),
|
||||||
|
imagePath: item['imagePath'] ?? '',
|
||||||
|
title: item['title'] ?? 'Tab to run',
|
||||||
|
deviceData: item,
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
onWillAccept: (data) => data != null,
|
onWillAccept: (data) => data != null,
|
||||||
onAccept: (data) async {
|
onAccept: (data) async {
|
||||||
final result =
|
if (!context.read<RoutineBloc>().isTabToRun) {
|
||||||
await DeviceDialogHelper.showDeviceDialog(context, data);
|
if (data['deviceId'] == 'tab_to_run') {
|
||||||
if (result != null) {
|
context.read<RoutineBloc>().add(AddToIfContainer(data, true));
|
||||||
context.read<RoutineBloc>().add(AddToIfContainer(result));
|
} else {
|
||||||
} else if (!['AC', '1G', '2G', '3G']
|
final result = await DeviceDialogHelper.showDeviceDialog(context, data);
|
||||||
.contains(data['productType'])) {
|
if (result != null) {
|
||||||
context.read<RoutineBloc>().add(AddToIfContainer(data));
|
context.read<RoutineBloc>().add(AddToIfContainer(result, false));
|
||||||
|
} else if (!['AC', '1G', '2G', '3G'].contains(data['productType'])) {
|
||||||
|
context.read<RoutineBloc>().add(AddToIfContainer(data, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user