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
This commit is contained in:
mohammad
2024-07-01 13:58:24 +03:00
parent 0bd6a5013d
commit dbdf9fca76
3 changed files with 12 additions and 7 deletions

View File

@ -18,6 +18,7 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
final String deviceId; final String deviceId;
late SmartDoorModel deviceStatus; late SmartDoorModel deviceStatus;
static String pageType = ''; static String pageType = '';
bool isSavingPassword = false;
SmartDoorBloc({required this.deviceId}) : super(InitialState()) { SmartDoorBloc({required this.deviceId}) : super(InitialState()) {
on<InitialEvent>(_fetchSmartDoorStatus); on<InitialEvent>(_fetchSmartDoorStatus);
@ -198,8 +199,9 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
} }
Future<void> savePassword(SavePasswordEvent event, Emitter<SmartDoorState> emit) async { Future<void> savePassword(SavePasswordEvent event, Emitter<SmartDoorState> emit) async {
if (_validateInputs()) return; if (_validateInputs() || isSavingPassword) return;
try { try {
isSavingPassword = true;
emit(LoadingSaveState()); emit(LoadingSaveState());
var res = await DevicesAPI.createPassword( var res = await DevicesAPI.createPassword(
pageType: pageType, pageType: pageType,
@ -220,9 +222,10 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
Navigator.of(event.context).pop(true); Navigator.of(event.context).pop(true);
CustomSnackBar.displaySnackBar('Save Successfully'); CustomSnackBar.displaySnackBar('Save Successfully');
emit(SaveState()); emit(SaveState());
} catch (_) {} } catch (_) {}finally {
isSavingPassword = false;
}
} }
Future<void> deletePassword(DeletePasswordEvent event, Emitter<SmartDoorState> emit) async { Future<void> deletePassword(DeletePasswordEvent event, Emitter<SmartDoorState> emit) async {
try { try {
emit(LoadingInitialState()); emit(LoadingInitialState());

View File

@ -47,14 +47,16 @@ class CreateTemporaryPassword extends StatelessWidget {
onPressed: () { onPressed: () {
Navigator.of(context).pop('UpdatePage'); Navigator.of(context).pop('UpdatePage');
}, },
icon: const Icon(Icons.arrow_back)), icon: const Icon(Icons.arrow_back)
),
actions: [ actions: [
TextButton( TextButton(
onPressed: () { onPressed: () {
BlocProvider.of<SmartDoorBloc>(context) BlocProvider.of<SmartDoorBloc>(context)
.add(SavePasswordEvent(context: context)); .add(SavePasswordEvent(context: context));
}, },
child: const Text('Save')) child: const Text('Save')
)
], ],
), ),
child: state is LoadingInitialState child: state is LoadingInitialState

View File

@ -32,12 +32,12 @@ class DoorDialogState extends State<DoorDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final DateTime effectiveDateTime = 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 formattedDateEffectiveTime = DateFormat('yyyy-MM-dd').format(effectiveDateTime);
String formattedTimeEffectiveTime = DateFormat('HH:mm:ss').format(effectiveDateTime); String formattedTimeEffectiveTime = DateFormat('HH:mm:ss').format(effectiveDateTime);
final DateTime expiredDateTime = 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 formattedDateExpiredDateTime = DateFormat('yyyy-MM-dd').format(expiredDateTime);
String formattedTimeExpiredDateTime = DateFormat('HH:mm:ss').format(expiredDateTime); String formattedTimeExpiredDateTime = DateFormat('HH:mm:ss').format(expiredDateTime);