mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
75 lines
2.6 KiB
Dart
75 lines
2.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
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/models/device_functions.dart';
|
|
import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart';
|
|
import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
|
|
|
class DelayHelper {
|
|
static Future<Map<String, dynamic>?> showDelayPickerDialog(
|
|
BuildContext context, String uniqueCustomId) async {
|
|
int hours = 0;
|
|
int minutes = 0;
|
|
|
|
return showDialog<Map<String, dynamic>?>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
contentPadding: EdgeInsets.zero,
|
|
content: Container(
|
|
width: 600,
|
|
height: 300,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const DialogHeader('Select Delay Duration'),
|
|
Expanded(
|
|
child: CupertinoTimerPicker(
|
|
mode: CupertinoTimerPickerMode.hm,
|
|
initialTimerDuration:
|
|
Duration(hours: hours, minutes: minutes),
|
|
onTimerDurationChanged: (Duration newDuration) {
|
|
hours = newDuration.inHours;
|
|
minutes = newDuration.inMinutes % 60;
|
|
},
|
|
),
|
|
),
|
|
DialogFooter(
|
|
onCancel: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
onConfirm: () {
|
|
int totalSeconds = (hours * 3600) + (minutes * 60);
|
|
context.read<RoutineBloc>().add(AddFunctionToRoutine(
|
|
[
|
|
DeviceFunctionData(
|
|
entityId: 'delay',
|
|
functionCode: 'delay',
|
|
operationName: 'Delay',
|
|
value: totalSeconds,
|
|
)
|
|
],
|
|
uniqueCustomId,
|
|
));
|
|
|
|
Navigator.pop(context, {
|
|
'deviceId': 'delay',
|
|
'value': totalSeconds,
|
|
});
|
|
},
|
|
isConfirmEnabled: true,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|