From dbdf9fca76ea39befdcd6e97c39cb5ed3a4f7139 Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 1 Jul 2024 13:58:24 +0300 Subject: [PATCH 1/2] fix this 17. The door lock/create password the screen, save button will create a pass as much the user click on the save button and Fixed the time being displayed incorrectly in DoorDialog --- .../devices/bloc/smart_door_bloc/smart_door_bloc.dart | 9 ++++++--- .../widgets/smart_door/create_temporary_password.dart | 6 ++++-- .../devices/view/widgets/smart_door/door_dialog.dart | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart b/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart index 37c3bf4..d1a310e 100644 --- a/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart +++ b/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart @@ -18,6 +18,7 @@ class SmartDoorBloc extends Bloc { final String deviceId; late SmartDoorModel deviceStatus; static String pageType = ''; + bool isSavingPassword = false; SmartDoorBloc({required this.deviceId}) : super(InitialState()) { on(_fetchSmartDoorStatus); @@ -198,8 +199,9 @@ class SmartDoorBloc extends Bloc { } Future savePassword(SavePasswordEvent event, Emitter emit) async { - if (_validateInputs()) return; + if (_validateInputs() || isSavingPassword) return; try { + isSavingPassword = true; emit(LoadingSaveState()); var res = await DevicesAPI.createPassword( pageType: pageType, @@ -220,9 +222,10 @@ class SmartDoorBloc extends Bloc { Navigator.of(event.context).pop(true); CustomSnackBar.displaySnackBar('Save Successfully'); emit(SaveState()); - } catch (_) {} + } catch (_) {}finally { + isSavingPassword = false; + } } - Future deletePassword(DeletePasswordEvent event, Emitter emit) async { try { emit(LoadingInitialState()); diff --git a/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart b/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart index 1d7e110..117f983 100644 --- a/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart +++ b/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart @@ -47,14 +47,16 @@ class CreateTemporaryPassword extends StatelessWidget { onPressed: () { Navigator.of(context).pop('UpdatePage'); }, - icon: const Icon(Icons.arrow_back)), + icon: const Icon(Icons.arrow_back) + ), actions: [ TextButton( onPressed: () { BlocProvider.of(context) .add(SavePasswordEvent(context: context)); }, - child: const Text('Save')) + child: const Text('Save') + ) ], ), child: state is LoadingInitialState diff --git a/lib/features/devices/view/widgets/smart_door/door_dialog.dart b/lib/features/devices/view/widgets/smart_door/door_dialog.dart index 867cbd1..c194693 100644 --- a/lib/features/devices/view/widgets/smart_door/door_dialog.dart +++ b/lib/features/devices/view/widgets/smart_door/door_dialog.dart @@ -32,12 +32,12 @@ class DoorDialogState extends State { @override Widget build(BuildContext context) { final DateTime effectiveDateTime = - DateTime.fromMillisecondsSinceEpoch(widget.value.effectiveTime * 1000, isUtc: true); + DateTime.fromMillisecondsSinceEpoch(widget.value.effectiveTime * 1000, isUtc: false); String formattedDateEffectiveTime = DateFormat('yyyy-MM-dd').format(effectiveDateTime); String formattedTimeEffectiveTime = DateFormat('HH:mm:ss').format(effectiveDateTime); final DateTime expiredDateTime = - DateTime.fromMillisecondsSinceEpoch(widget.value.invalidTime * 1000, isUtc: true); + DateTime.fromMillisecondsSinceEpoch(widget.value.invalidTime * 1000, isUtc: false); String formattedDateExpiredDateTime = DateFormat('yyyy-MM-dd').format(expiredDateTime); String formattedTimeExpiredDateTime = DateFormat('HH:mm:ss').format(expiredDateTime); From a802fd29551d48efdbb0ed1becf698a378326db3 Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 1 Jul 2024 15:41:53 +0300 Subject: [PATCH 2/2] All characters cannot be 1 --- .../bloc/smart_door_bloc/smart_door_bloc.dart | 3 +-- .../smart_door/create_temporary_password.dart | 13 +++++++++---- .../view/widgets/smart_door/door_dialog.dart | 3 --- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart b/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart index d1a310e..811953d 100644 --- a/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart +++ b/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart @@ -185,8 +185,7 @@ class SmartDoorBloc extends Bloc { } } else { if (effectiveTimeTimeStamp != null && selectedTimestamp < effectiveTimeTimeStamp!) { - CustomSnackBar.displaySnackBar( - 'Expiration Time cannot be earlier than Effective Time.'); + CustomSnackBar.displaySnackBar('Expiration Time cannot be earlier than Effective Time.'); } else { expirationTime = selectedDateTime.toString().split('.').first; // Remove seconds and milliseconds diff --git a/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart b/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart index 117f983..0cf50f7 100644 --- a/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart +++ b/lib/features/devices/view/widgets/smart_door/create_temporary_password.dart @@ -11,6 +11,7 @@ import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; +import 'package:syncrow_app/utils/helpers/snack_bar.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/font_manager.dart'; import 'package:time_picker_spinner/time_picker_spinner.dart'; @@ -67,8 +68,7 @@ class CreateTemporaryPassword extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ const BodyMedium( - text: - 'Save the password immediately. The password is not displayed in the app.', + text: 'Save the password immediately. The password is not displayed in the app.', fontWeight: FontWeight.normal, fontColor: ColorsManager.grayColor, ), @@ -89,6 +89,12 @@ class CreateTemporaryPassword extends StatelessWidget { Flexible( flex: 2, child: PinCodeTextField( + onCompleted: (value) { + if (value.split('').every((char) => char == '1')) { + BlocProvider.of(context).passwordController.clear(); + CustomSnackBar.displaySnackBar('All characters cannot be 1.'); + } + }, autoDisposeControllers: false, keyboardType: TextInputType.phone, length: 7, @@ -109,8 +115,7 @@ class CreateTemporaryPassword extends StatelessWidget { animationDuration: const Duration(milliseconds: 300), backgroundColor: Colors.white, enableActiveFill: false, - controller: - BlocProvider.of(context).passwordController, + controller: BlocProvider.of(context).passwordController, appContext: context, )), const SizedBox( diff --git a/lib/features/devices/view/widgets/smart_door/door_dialog.dart b/lib/features/devices/view/widgets/smart_door/door_dialog.dart index c194693..39d83b9 100644 --- a/lib/features/devices/view/widgets/smart_door/door_dialog.dart +++ b/lib/features/devices/view/widgets/smart_door/door_dialog.dart @@ -1,11 +1,8 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; -import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/temporary_password_model.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; -import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart'; import 'package:syncrow_app/utils/context_extension.dart'; -import 'package:syncrow_app/utils/helpers/snack_bar.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/font_manager.dart';