mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-26 04:27:54 +00:00
door lock changes
This commit is contained in:
@@ -31,7 +31,25 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
on<GeneratePasswordEvent>(generate7DigitNumber);
|
||||
on<SelectTimeEvent>(selectTime);
|
||||
on<DeletePasswordEvent>(deletePassword);
|
||||
on<GenerateAndSavePasswordTimeLimitEvent>(generateAndSavePasswordTimeLimited);
|
||||
on<GenerateAndSavePasswordOneTimeEvent>(generateAndSavePasswordOneTime);
|
||||
}
|
||||
|
||||
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
TextEditingController passwordNameController = TextEditingController();
|
||||
String effectiveTime = 'Select Time';
|
||||
int? effectiveTimeTimeStamp;
|
||||
String expirationTime = 'Select Time';
|
||||
int? expirationTimeTimeStamp;
|
||||
bool repeat = false;
|
||||
bool isStartEndTime = true;
|
||||
List<String>? selectedDay;
|
||||
DateTime? startTime;
|
||||
DateTime? endTime;
|
||||
List<TemporaryPassword>? temporaryPasswords = [];
|
||||
List<TemporaryPassword>? oneTimePasswords = [];
|
||||
|
||||
void _fetchSmartDoorStatus(InitialEvent event, Emitter<SmartDoorState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
@@ -58,8 +76,6 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
} else if (response is Map && response.containsKey('data')) {
|
||||
temporaryPasswords =
|
||||
(response['data'] as List).map((item) => TemporaryPassword.fromJson(item)).toList();
|
||||
} else {
|
||||
throw Exception("Unexpected response format");
|
||||
}
|
||||
emit(TemporaryPasswordsLoadedState(temporaryPassword: temporaryPasswords!));
|
||||
} catch (e) {
|
||||
@@ -67,20 +83,6 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
}
|
||||
}
|
||||
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
TextEditingController passwordNameController = TextEditingController();
|
||||
String effectiveTime = 'Select Time';
|
||||
int? effectiveTimeTimeStamp;
|
||||
String expirationTime = 'Select Time';
|
||||
int? expirationTimeTimeStamp;
|
||||
bool repeat = false;
|
||||
bool isStartEndTime = true;
|
||||
List<String>? selectedDay;
|
||||
DateTime? startTime;
|
||||
DateTime? endTime;
|
||||
List<TemporaryPassword>? temporaryPasswords = [];
|
||||
List<TemporaryPassword>? oneTimePasswords = [];
|
||||
|
||||
changeTime(ChangeTimeEvent event, Emitter<SmartDoorState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
if (event.isStartEndTime == true) {
|
||||
@@ -225,6 +227,66 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
isSavingPassword = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> generateAndSavePasswordTimeLimited (GenerateAndSavePasswordTimeLimitEvent event, Emitter<SmartDoorState> emit) async {
|
||||
if (_validateInputs() || isSavingPassword) return;
|
||||
try {
|
||||
isSavingPassword = true;
|
||||
emit(LoadingSaveState());
|
||||
var res = await DevicesAPI.createPassword(
|
||||
pageType: pageType,
|
||||
deviceId: deviceId,
|
||||
effectiveTime: effectiveTimeTimeStamp.toString(),
|
||||
invalidTime: expirationTimeTimeStamp.toString(),
|
||||
name: passwordNameController.text,
|
||||
password: passwordController.text,
|
||||
scheduleList: [
|
||||
if (repeat)
|
||||
Schedule(
|
||||
effectiveTime: getTimeOnly(startTime),
|
||||
invalidTime: getTimeOnly(endTime).toString(),
|
||||
workingDay: selectedDay!,
|
||||
),
|
||||
],
|
||||
);
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(SaveState());
|
||||
} catch (_) {}finally {
|
||||
isSavingPassword = false;
|
||||
}
|
||||
}
|
||||
Future<void> generateAndSavePasswordOneTime (GenerateAndSavePasswordOneTimeEvent event, Emitter<SmartDoorState> emit) async {
|
||||
try {
|
||||
if (passwordNameController.text.isEmpty) {
|
||||
CustomSnackBar.displaySnackBar('Password name required');
|
||||
}else {
|
||||
if (isSavingPassword) return;
|
||||
isSavingPassword = true;
|
||||
emit(LoadingSaveState());
|
||||
var res = await DevicesAPI.createPassword(
|
||||
pageType: pageType,
|
||||
deviceId: deviceId,
|
||||
effectiveTime: effectiveTimeTimeStamp.toString(),
|
||||
invalidTime: expirationTimeTimeStamp.toString(),
|
||||
name: passwordNameController.text,
|
||||
password: passwordController.text,
|
||||
scheduleList: [
|
||||
if (repeat)
|
||||
Schedule(
|
||||
effectiveTime: getTimeOnly(startTime),
|
||||
invalidTime: getTimeOnly(endTime).toString(),
|
||||
workingDay: selectedDay!,
|
||||
),
|
||||
],
|
||||
);
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(SaveState());
|
||||
}
|
||||
} catch (_) {}finally {
|
||||
isSavingPassword = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deletePassword(DeletePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
@@ -239,11 +301,11 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
}
|
||||
|
||||
bool _validateInputs() {
|
||||
if (passwordController.text.length < 7) {
|
||||
if (passwordController.text.length < 7 && pageType=='Online Password') {
|
||||
CustomSnackBar.displaySnackBar('Password less than 7');
|
||||
return true;
|
||||
}
|
||||
if (passwordController.text.isEmpty) {
|
||||
if (passwordController.text.isEmpty && pageType=='Online Password') {
|
||||
CustomSnackBar.displaySnackBar('Password required');
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,8 +28,23 @@ class SavePasswordEvent extends SmartDoorEvent {
|
||||
@override
|
||||
List<Object> get props => [context];
|
||||
}
|
||||
class GenerateAndSavePasswordTimeLimitEvent extends SmartDoorEvent {
|
||||
final BuildContext context;
|
||||
const GenerateAndSavePasswordTimeLimitEvent({required this.context});
|
||||
@override
|
||||
List<Object> get props => [context];
|
||||
}
|
||||
|
||||
class GeneratePasswordEvent extends SmartDoorEvent {}
|
||||
class GenerateAndSavePasswordOneTimeEvent extends SmartDoorEvent {
|
||||
final BuildContext context;
|
||||
const GenerateAndSavePasswordOneTimeEvent({required this.context});
|
||||
@override
|
||||
List<Object> get props => [context];
|
||||
}
|
||||
|
||||
class GeneratePasswordEvent extends SmartDoorEvent {
|
||||
|
||||
}
|
||||
class SelectTimeEvent extends SmartDoorEvent {
|
||||
final BuildContext context;
|
||||
final bool isEffective;
|
||||
|
||||
Reference in New Issue
Block a user