From ae47e4883204f3f9481aa56aa85a7d9813d3295f Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Wed, 26 Jun 2024 15:55:40 +0300 Subject: [PATCH] push countdown widget --- lib/features/devices/model/functions.dart | 58 ------------------- lib/features/scene/helper/scene_helper.dart | 12 +++- .../scene/view/device_functions_view.dart | 11 +++- .../scene/widgets/alert_dialog_countdown.dart | 27 +++++++-- .../widgets/alert_dialog_functions_body.dart | 2 +- .../scene/widgets/scene_list_tile.dart | 6 +- pubspec.yaml | 1 + 7 files changed, 45 insertions(+), 72 deletions(-) delete mode 100644 lib/features/devices/model/functions.dart diff --git a/lib/features/devices/model/functions.dart b/lib/features/devices/model/functions.dart deleted file mode 100644 index cd1b209..0000000 --- a/lib/features/devices/model/functions.dart +++ /dev/null @@ -1,58 +0,0 @@ -class FunctionsEntity { - final String productUuid; - final String productType; - final List functions; - - FunctionsEntity({ - required this.productUuid, - required this.productType, - required this.functions, - }); - - factory FunctionsEntity.fromJson(Map json) => - FunctionsEntity( - productUuid: json["productUuid"], - productType: json["productType"], - functions: List.from( - json["functions"].map((x) => DeviceFunction.fromJson(x)), - ), - ); - - Map toJson() => { - "productUuid": productUuid, - "productType": productType, - "functions": List.from(functions.map((x) => x.toJson())), - }; -} - -class DeviceFunction { - final String code; - final String values; - final String dataType; - - DeviceFunction({ - required this.code, - required this.values, - required this.dataType, - }); - - factory DeviceFunction.fromJson(Map json) => DeviceFunction( - code: _formatCode(json["code"]), - values: json["values"], - dataType: json["dataType"], - ); - - Map toJson() => { - "code": code, - "values": values, - "dataType": dataType, - }; - - static String _formatCode(String originalCode) { - return originalCode - .replaceAll('_', ' ') - .split(' ') - .map((word) => word[0].toUpperCase() + word.substring(1)) - .join(' '); - } -} diff --git a/lib/features/scene/helper/scene_helper.dart b/lib/features/scene/helper/scene_helper.dart index eadef9a..ccfc555 100644 --- a/lib/features/scene/helper/scene_helper.dart +++ b/lib/features/scene/helper/scene_helper.dart @@ -149,19 +149,25 @@ List threeGangFunctions(List functions) { icon: Assets.assetsLightCountdown, name: 'Light 1 CountDown', code: 'countdown_1', - operationalValues: [], + operationalValues: [ + StaticFunctionOperationHelper(icon: '', value: "12610"), + ], ), SceneStaticFunction( icon: Assets.assetsLightCountdown, name: 'Light 2 CountDown', code: 'countdown_1', - operationalValues: [], + operationalValues: [ + StaticFunctionOperationHelper(icon: '', value: "0"), + ], ), SceneStaticFunction( icon: Assets.assetsLightCountdown, name: 'Light 3 CountDown', code: 'countdown_1', - operationalValues: [], + operationalValues: [ + StaticFunctionOperationHelper(icon: '', value: "0"), + ], ), ]; } diff --git a/lib/features/scene/view/device_functions_view.dart b/lib/features/scene/view/device_functions_view.dart index 2a955a5..fd5fe91 100644 --- a/lib/features/scene/view/device_functions_view.dart +++ b/lib/features/scene/view/device_functions_view.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/scene/helper/scene_helper.dart'; import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; +import 'package:syncrow_app/features/scene/widgets/alert_dialog_countdown.dart'; import 'package:syncrow_app/features/scene/widgets/alert_dialog_functions_body.dart'; import 'package:syncrow_app/features/scene/widgets/alert_dialog_temperature_body.dart'; import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart'; @@ -102,8 +103,14 @@ class DeviceFunctionsView extends StatelessWidget with SceneHelper { alertBody: functions[index].code == 'temp_set' ? AlertDialogTemperatureBody( index: index, functions: functions) - : AlertDialogFunctionsOperationsBody( - index: index, functions: functions), + : functions[index].code.contains('countdown') + ? AlertDialogCountdown( + durationValue: functions[index] + .operationalValues + .first + .value) + : AlertDialogFunctionsOperationsBody( + index: index, functions: functions), title: functions[index].name, onConfirm: () {}, ); diff --git a/lib/features/scene/widgets/alert_dialog_countdown.dart b/lib/features/scene/widgets/alert_dialog_countdown.dart index 03a041e..6feadfa 100644 --- a/lib/features/scene/widgets/alert_dialog_countdown.dart +++ b/lib/features/scene/widgets/alert_dialog_countdown.dart @@ -1,19 +1,36 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; + class AlertDialogCountdown extends StatefulWidget { - const AlertDialogCountdown({super.key}); + const AlertDialogCountdown({super.key, required this.durationValue}); + + final String durationValue; @override State createState() => _AlertDialogCountdownState(); } class _AlertDialogCountdownState extends State { + int durationInSeconds = 0; + // Convert seconds to Duration. + Duration get duration => + Duration(seconds: int.tryParse(widget.durationValue) ?? 0); @override Widget build(BuildContext context) { - return Row( - children: [ - - ], + return Container( + height: 120, + color: Colors.white, + child: CupertinoTimerPicker( + itemExtent: 120, + mode: CupertinoTimerPickerMode.hm, + initialTimerDuration: duration, + onTimerDurationChanged: (newDuration) { + setState(() { + durationInSeconds = newDuration.inSeconds; + }); + }, + ), ); } } diff --git a/lib/features/scene/widgets/alert_dialog_functions_body.dart b/lib/features/scene/widgets/alert_dialog_functions_body.dart index a4237a1..679060a 100644 --- a/lib/features/scene/widgets/alert_dialog_functions_body.dart +++ b/lib/features/scene/widgets/alert_dialog_functions_body.dart @@ -28,7 +28,7 @@ class _AlertDialogFunctionsOperationsBodyState children: [ ...widget.functions[widget.index].operationalValues.map( (operation) => SceneListTile( - iconsSize: 22, + iconsSize: 25, minLeadingWidth: 15, padding: const EdgeInsets.symmetric(horizontal: 16), assetPath: operation.icon, diff --git a/lib/features/scene/widgets/scene_list_tile.dart b/lib/features/scene/widgets/scene_list_tile.dart index 4cb6f42..ea940aa 100644 --- a/lib/features/scene/widgets/scene_list_tile.dart +++ b/lib/features/scene/widgets/scene_list_tile.dart @@ -47,10 +47,10 @@ class SceneListTile extends StatelessWidget { width: iconsSize, child: SvgPicture.asset( assetPath ?? Assets.assetsImagesLogo, - width: 20, - height: assetHeight ?? 32, + width: iconsSize, + height: assetHeight ?? 35, alignment: Alignment.center, - fit: BoxFit.fill, + fit: BoxFit.contain, ), ) : null), diff --git a/pubspec.yaml b/pubspec.yaml index 3027c5d..a50acf6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: permission_handler: ^11.3.1 pin_code_fields: ^8.0.1 share_plus: ^9.0.0 + dev_dependencies: flutter_test: