mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-23 13:07:56 +00:00
door lock
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/offline_temporary_password.dart';
|
||||
import 'package:syncrow_app/features/devices/model/smart_door_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/create_temporary_password_model.dart';
|
||||
@@ -33,11 +34,13 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
on<GenerateAndSavePasswordTimeLimitEvent>(generateAndSavePasswordTimeLimited);
|
||||
on<GenerateAndSavePasswordOneTimeEvent>(generateAndSavePasswordOneTime);
|
||||
on<ToggleDaySelectionEvent>(toggleDaySelection);
|
||||
on<RenamePasswordEvent>(_renamePassword);
|
||||
}
|
||||
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
TextEditingController passwordNameController = TextEditingController();
|
||||
String effectiveTime = 'Select Time';
|
||||
String passwordId = '';
|
||||
int? effectiveTimeTimeStamp;
|
||||
String expirationTime = 'Select Time';
|
||||
int? expirationTimeTimeStamp;
|
||||
@@ -60,18 +63,20 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
}
|
||||
|
||||
|
||||
Future<void> generateAndSavePasswordOneTime (GenerateAndSavePasswordOneTimeEvent event, Emitter<SmartDoorState> emit) async {
|
||||
Future generateAndSavePasswordOneTime (GenerateAndSavePasswordOneTimeEvent event, Emitter<SmartDoorState> emit) async {
|
||||
try {
|
||||
if (isSavingPassword) return;
|
||||
isSavingPassword = true;
|
||||
emit(LoadingInitialState());
|
||||
Future.delayed(const Duration(milliseconds: 800), () {
|
||||
add(GeneratePasswordEvent());
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
});
|
||||
emit(const GeneratePasswordOneTimestate(generated: true));
|
||||
var res = await DevicesAPI.generateOneTimePassword(deviceId: deviceId);
|
||||
ApiResponse pass= ApiResponse.fromJson(res);
|
||||
passwordController.text =pass.data.offlineTempPassword;
|
||||
passwordId=pass.data.offlineTempPasswordId;
|
||||
emit(const GeneratePasswordOneTimestate(generated: true));
|
||||
|
||||
} catch (_) {}finally {
|
||||
} catch (_) {
|
||||
emit(FailedState(errorMessage: _.toString()));
|
||||
}finally {
|
||||
isSavingPassword = false;
|
||||
}
|
||||
}
|
||||
@@ -92,9 +97,25 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _renamePassword(RenamePasswordEvent event, Emitter<SmartDoorState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
var response = await DevicesAPI.renamePass(
|
||||
name:passwordNameController.text ,
|
||||
deviceId:deviceId ,
|
||||
passwordId:passwordId
|
||||
);
|
||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(FailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void getTemporaryPasswords(InitialPasswordsPage event, Emitter<SmartDoorState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
print('deviceId=$deviceId');
|
||||
pageType = event.type!;
|
||||
var response = await DevicesAPI.getTemporaryPasswords(deviceId, pageType);
|
||||
if (response is List) {
|
||||
@@ -238,7 +259,9 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
Navigator.of(event.context).pop(true);
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(SaveState());
|
||||
} catch (_) {}finally {
|
||||
} catch (_) {
|
||||
|
||||
}finally {
|
||||
isSavingPassword = false;
|
||||
}
|
||||
}
|
||||
@@ -248,11 +271,14 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
try {
|
||||
isSavingPassword = true;
|
||||
emit(LoadingInitialState());
|
||||
Future.delayed(const Duration(milliseconds: 800), () {
|
||||
add(GeneratePasswordEvent());
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(const GeneratePasswordOneTimestate(generated: true));
|
||||
});
|
||||
var res = await DevicesAPI.generateMultiTimePassword(deviceId: deviceId,
|
||||
effectiveTime: effectiveTimeTimeStamp.toString(),
|
||||
invalidTime: expirationTimeTimeStamp.toString(), );
|
||||
ApiResponse pass= ApiResponse.fromJson(res);
|
||||
passwordController.text =pass.data.offlineTempPassword;
|
||||
passwordId=pass.data.offlineTempPasswordId;
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(const GeneratePasswordOneTimestate(generated: true));
|
||||
} catch (_) {
|
||||
print(_);
|
||||
}
|
||||
|
||||
@@ -88,4 +88,7 @@ class ChangeTimeEvent extends SmartDoorEvent {
|
||||
List<Object> get props => [val,isStartEndTime];
|
||||
}
|
||||
|
||||
class RenamePasswordEvent extends SmartDoorEvent {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
class OfflineTemporaryPassword {
|
||||
dynamic effectiveTime;
|
||||
dynamic invalidTime;
|
||||
dynamic offlineTempPassword;
|
||||
dynamic offlineTempPasswordId;
|
||||
dynamic offlineTempPasswordName;
|
||||
|
||||
OfflineTemporaryPassword({
|
||||
required this.effectiveTime,
|
||||
required this.invalidTime,
|
||||
required this.offlineTempPassword,
|
||||
required this.offlineTempPasswordId,
|
||||
required this.offlineTempPasswordName,
|
||||
});
|
||||
|
||||
factory OfflineTemporaryPassword.fromJson(Map<String, dynamic> json) {
|
||||
return OfflineTemporaryPassword(
|
||||
effectiveTime: json['effective_time'],
|
||||
invalidTime: json['invalid_time'],
|
||||
offlineTempPassword: json['offline_temp_password'],
|
||||
offlineTempPasswordId: json['offline_temp_password_id'],
|
||||
offlineTempPasswordName: json['offline_temp_password_name'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'effective_time': effectiveTime,
|
||||
'invalid_time': invalidTime,
|
||||
'offline_temp_password': offlineTempPassword,
|
||||
'offline_temp_password_id': offlineTempPasswordId,
|
||||
'offline_temp_password_name': offlineTempPasswordName,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class ApiResponse {
|
||||
int statusCode;
|
||||
bool success;
|
||||
String message;
|
||||
OfflineTemporaryPassword data;
|
||||
|
||||
ApiResponse({
|
||||
required this.statusCode,
|
||||
required this.success,
|
||||
required this.message,
|
||||
required this.data,
|
||||
});
|
||||
|
||||
factory ApiResponse.fromJson(Map<String, dynamic> json) {
|
||||
return ApiResponse(
|
||||
statusCode: json['statusCode'],
|
||||
success: json['success'],
|
||||
message: json['message'],
|
||||
data: OfflineTemporaryPassword.fromJson(json['data']['result']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'statusCode': statusCode,
|
||||
'success': success,
|
||||
'message': message,
|
||||
'data': {
|
||||
'result': data.toJson(),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -200,6 +200,9 @@ class OfflineOneTimePasswordPage extends StatelessWidget {
|
||||
if(generated==false){
|
||||
smartDoorBloc.add(GenerateAndSavePasswordOneTimeEvent(context: context));
|
||||
}else{
|
||||
if(smartDoorBloc.passwordNameController.text.isNotEmpty){
|
||||
smartDoorBloc.add(RenamePasswordEvent());
|
||||
}
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -163,7 +163,6 @@ class CreateTemporaryPassword extends StatelessWidget {
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
type == 'Online Password'?
|
||||
DefaultContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
child: ListTile(
|
||||
@@ -182,33 +181,7 @@ class CreateTemporaryPassword extends StatelessWidget {
|
||||
applyTheme: true,
|
||||
)),
|
||||
),
|
||||
) :
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: MediaQuery.of(context).size.width/1.5,
|
||||
child: DefaultButton(
|
||||
isDone: generated,
|
||||
isLoading: smartDoorBloc.isSavingPassword ,
|
||||
borderRadius: 30,
|
||||
backgroundColor:Colors.blueGrey ,
|
||||
onPressed: () {
|
||||
if(generated==false){
|
||||
if(type =='Time-Limited'){
|
||||
smartDoorBloc.add(GenerateAndSavePasswordTimeLimitEvent(context: context));
|
||||
}else{
|
||||
smartDoorBloc.add(GenerateAndSavePasswordOneTimeEvent(context: context));
|
||||
}
|
||||
}else{
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
child: const BodyMedium(
|
||||
text: 'Generate & Save Password',
|
||||
fontWeight: FontWeight.normal,
|
||||
fontColor: Colors.white,
|
||||
),),
|
||||
),
|
||||
),
|
||||
) ,
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
|
||||
@@ -264,6 +264,9 @@ class OfflineTimeLimitPasswordPage extends StatelessWidget {
|
||||
GenerateAndSavePasswordTimeLimitEvent(
|
||||
context: context));
|
||||
} else {
|
||||
if(smartDoorBloc.passwordNameController.text.isNotEmpty){
|
||||
smartDoorBloc.add(RenamePasswordEvent());
|
||||
}
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user