door lock

This commit is contained in:
mohammad
2024-07-24 16:58:50 +03:00
parent 7495c0f67e
commit b6053e1ceb
10 changed files with 176 additions and 57 deletions

View File

@ -291,4 +291,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: cf86fcba3fb3dbd505936bc190bb0b8fe3dd2498
COCOAPODS: 1.14.3
COCOAPODS: 1.15.2

View File

@ -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(_);
}

View File

@ -88,4 +88,7 @@ class ChangeTimeEvent extends SmartDoorEvent {
List<Object> get props => [val,isStartEndTime];
}
class RenamePasswordEvent extends SmartDoorEvent {
}

View File

@ -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(),
},
};
}
}

View File

@ -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);
}
},

View File

@ -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,
),

View File

@ -264,6 +264,9 @@ class OfflineTimeLimitPasswordPage extends StatelessWidget {
GenerateAndSavePasswordTimeLimitEvent(
context: context));
} else {
if(smartDoorBloc.passwordNameController.text.isNotEmpty){
smartDoorBloc.add(RenamePasswordEvent());
}
Navigator.pop(context);
}
},

View File

@ -1,5 +1,5 @@
abstract class ApiEndpoints {
static const String baseUrl = 'https://syncrow.azurewebsites.net';
static const String baseUrl = 'https://syncrow-dev.azurewebsites.net';
// static const String baseUrl = 'http://100.107.182.63:4001'; //Localhost
////////////////////////////////////// Authentication ///////////////////////////////
@ -148,6 +148,9 @@ abstract class ApiEndpoints {
static const String getMultipleTimeTemporaryPassword =
'$baseUrl/door-lock/temporary-password/offline/multiple-time/{doorLockUuid}';
static const String renamePassword =
'$baseUrl/door-lock/temporary-password/{doorLockUuid}/offline/{passwordId}';
//multiple-time offline
static const String deleteTemporaryPassword =
'$baseUrl/door-lock/temporary-password/{doorLockUuid}/{passwordId}';

View File

@ -3,6 +3,7 @@ import 'package:syncrow_app/features/devices/model/device_category_model.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/function_model.dart';
import 'package:syncrow_app/features/devices/model/offline_temporary_password.dart';
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
import 'package:syncrow_app/services/api/http_service.dart';
@ -69,6 +70,22 @@ class DevicesAPI {
return response;
}
static Future<Map<String, dynamic>> renamePass({
required String name,
required String deviceId,
required String passwordId}) async {
final response = await _httpService.put(
path: ApiEndpoints.renamePassword.replaceAll('{deviceUuid}', deviceId).replaceAll('{passwordId}', passwordId),
body: {
"name": name
},
expectedResponseModel: (json) {
return json;
},
);
return response;
}
/// Get Device Functions
static Future<FunctionModel> deviceFunctions(String deviceId) async {
final response = await _httpService.get(
@ -140,12 +157,8 @@ class DevicesAPI {
static Future getTemporaryPasswords(String deviceId, pageType) async {
final response = await _httpService.get(
path: pageType == 'One-Time'
? ApiEndpoints.getOneTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId)
: pageType == 'Online Password'
? ApiEndpoints.getTemporaryPassword.replaceAll('{doorLockUuid}', deviceId)
: ApiEndpoints.getMultipleTimeTemporaryPassword
.replaceAll('{doorLockUuid}', deviceId),
path:
ApiEndpoints.getTemporaryPassword.replaceAll('{doorLockUuid}', deviceId),
showServerMessage: false,
expectedResponseModel: (json) {
return json;
@ -190,6 +203,40 @@ class DevicesAPI {
return response;
}
static Future generateOneTimePassword({deviceId}) async {
try {
final response = await _httpService.post(
path: ApiEndpoints.addOneTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId),
showServerMessage: false,
expectedResponseModel: (json) {
return json;
},
);
return response;
} catch (e) {
rethrow;
}
}
static Future generateMultiTimePassword({deviceId,effectiveTime,invalidTime}) async {
try {
final response = await _httpService.post(
path: ApiEndpoints.addMultipleTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId),
showServerMessage: false,
body: {
"effectiveTime": effectiveTime,
"invalidTime": invalidTime
},
expectedResponseModel: (json) {
return json;
},
);
return response;
} catch (e) {
rethrow;
}
}
static Future<Map<String, dynamic>> deletePassword(
{required String passwordId, required String deviceId}) async {
final response = await _httpService.delete(

View File

@ -842,14 +842,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.0"
time_picker_spinner:
dependency: "direct main"
description:
name: time_picker_spinner
sha256: "53d824801d108890d22756501e7ade9db48b53dac1ec41580499dd4ebd128e3c"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
typed_data:
dependency: transitive
description: