mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 19:34:55 +00:00
push connecting to automation api
This commit is contained in:
@ -5,12 +5,14 @@ class DialogFooter extends StatelessWidget {
|
||||
final VoidCallback onCancel;
|
||||
final VoidCallback? onConfirm;
|
||||
final bool isConfirmEnabled;
|
||||
final int? dialogWidth;
|
||||
|
||||
const DialogFooter({
|
||||
Key? key,
|
||||
required this.onCancel,
|
||||
required this.onConfirm,
|
||||
required this.isConfirmEnabled,
|
||||
this.dialogWidth,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -26,24 +28,23 @@ class DialogFooter extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_buildFooterButton(
|
||||
context,
|
||||
'Cancel',
|
||||
onCancel,
|
||||
width: isConfirmEnabled ? 299 : 179,
|
||||
),
|
||||
if (isConfirmEnabled)
|
||||
Row(
|
||||
children: [
|
||||
Container(width: 1, height: 50, color: ColorsManager.greyColor),
|
||||
_buildFooterButton(
|
||||
context,
|
||||
'Confirm',
|
||||
onConfirm,
|
||||
width: 299,
|
||||
),
|
||||
],
|
||||
Expanded(
|
||||
child: _buildFooterButton(
|
||||
context,
|
||||
'Cancel',
|
||||
onCancel,
|
||||
),
|
||||
),
|
||||
if (isConfirmEnabled) ...[
|
||||
Container(width: 1, height: 50, color: ColorsManager.greyColor),
|
||||
Expanded(
|
||||
child: _buildFooterButton(
|
||||
context,
|
||||
'Confirm',
|
||||
onConfirm,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -52,14 +53,12 @@ class DialogFooter extends StatelessWidget {
|
||||
Widget _buildFooterButton(
|
||||
BuildContext context,
|
||||
String text,
|
||||
VoidCallback? onTap, {
|
||||
required double width,
|
||||
}) {
|
||||
VoidCallback? onTap,
|
||||
) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: SizedBox(
|
||||
height: 50,
|
||||
width: width,
|
||||
child: Center(
|
||||
child: Text(
|
||||
text,
|
||||
|
||||
@ -124,34 +124,6 @@ class AutomationOperatorSelector extends StatelessWidget {
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: selectedOperator == 'and'
|
||||
? ColorsManager.dialogBlueTitle
|
||||
: ColorsManager.whiteColors,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(0),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'All condition is met',
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: selectedOperator == 'and'
|
||||
? ColorsManager.whiteColors
|
||||
: ColorsManager.blackColor,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
.add(const ChangeAutomationOperator(operator: 'and'));
|
||||
},
|
||||
),
|
||||
Container(
|
||||
width: 3,
|
||||
height: 24,
|
||||
color: ColorsManager.dividerColor,
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: selectedOperator == 'or'
|
||||
@ -175,6 +147,34 @@ class AutomationOperatorSelector extends StatelessWidget {
|
||||
.add(const ChangeAutomationOperator(operator: 'or'));
|
||||
},
|
||||
),
|
||||
Container(
|
||||
width: 3,
|
||||
height: 24,
|
||||
color: ColorsManager.dividerColor,
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: selectedOperator == 'and'
|
||||
? ColorsManager.dialogBlueTitle
|
||||
: ColorsManager.whiteColors,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(0),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'All condition is met',
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: selectedOperator == 'and'
|
||||
? ColorsManager.whiteColors
|
||||
: ColorsManager.blackColor,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
.add(const ChangeAutomationOperator(operator: 'and'));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@ -5,18 +5,19 @@ 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/widgets/dialog_header.dart';
|
||||
import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
|
||||
class AutomationDialog extends StatefulWidget {
|
||||
final String automationName;
|
||||
final String automationId;
|
||||
final String uniqueCustomId;
|
||||
|
||||
const AutomationDialog({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.automationName,
|
||||
required this.automationId,
|
||||
}) : super(key: key);
|
||||
required this.uniqueCustomId,
|
||||
});
|
||||
|
||||
@override
|
||||
_AutomationDialogState createState() => _AutomationDialogState();
|
||||
@ -72,18 +73,19 @@ class _AutomationDialogState extends State<AutomationDialog> {
|
||||
[
|
||||
DeviceFunctionData(
|
||||
entityId: widget.automationId,
|
||||
functionCode: '',
|
||||
functionCode: 'automation',
|
||||
value: _isEnabled,
|
||||
operationName: 'Automation',
|
||||
),
|
||||
],
|
||||
widget.automationId,
|
||||
widget.uniqueCustomId,
|
||||
),
|
||||
);
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
onCancel: () => Navigator.of(context).pop(false),
|
||||
isConfirmEnabled: true,
|
||||
dialogWidth: 400,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -94,20 +94,21 @@ class ThenContainer extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
},
|
||||
onWillAcceptWithDetails: (data) {
|
||||
if (data == null) return false;
|
||||
// onWillAcceptWithDetails: (data) {
|
||||
// if (data == null) return false;
|
||||
// return data.data;
|
||||
|
||||
if (state.isTabToRun) {
|
||||
return data.data['type'] == 'automation';
|
||||
}
|
||||
// // if (state.isTabToRun) {
|
||||
// // return data.data['type'] == 'automation';
|
||||
// // }
|
||||
|
||||
if (state.isAutomation) {
|
||||
return data.data['type'] == 'scene' ||
|
||||
data.data['type'] == 'automation';
|
||||
}
|
||||
// // if (state.isAutomation) {
|
||||
// // return data.data['type'] == 'scene' ||
|
||||
// // data.data['type'] == 'automation';
|
||||
// // }
|
||||
|
||||
return data.data['deviceId'] != null;
|
||||
},
|
||||
// // return data.data['deviceId'] != null;
|
||||
// },
|
||||
onAcceptWithDetails: (data) async {
|
||||
final uniqueCustomId = const Uuid().v4();
|
||||
final mutableData = Map<String, dynamic>.from(data.data);
|
||||
@ -124,13 +125,16 @@ class ThenContainer extends StatelessWidget {
|
||||
builder: (BuildContext context) => AutomationDialog(
|
||||
automationName: mutableData['name'] ?? 'Automation',
|
||||
automationId: mutableData['deviceId'] ?? '',
|
||||
uniqueCustomId: uniqueCustomId,
|
||||
),
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
.add(AddToThenContainer(mutableData));
|
||||
context.read<RoutineBloc>().add(AddToThenContainer({
|
||||
...mutableData,
|
||||
'imagePath': Assets.automation,
|
||||
'title': mutableData['name'],
|
||||
}));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user