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..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 @@ -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); @@ -184,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 @@ -198,8 +198,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 +221,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..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'; @@ -47,14 +48,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 @@ -65,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, ), @@ -87,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, @@ -107,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 867cbd1..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'; @@ -32,12 +29,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);