Skip to content

Commit

Permalink
bugFix: show snackbar for long period #1781
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Aug 14, 2023
1 parent 650966a commit 66efe59
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/app/shared/alert_message/alert_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AlertMessage {
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(milliseconds: 2 * 800),
duration: stateMessage.duration,
content: SnackBarContent(
message: message,
iconPath: stateMessage.type.iconPath,
Expand Down
16 changes: 14 additions & 2 deletions lib/app/shared/models/state_message/state_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class StateMessage extends Equatable {
this.stringMessage,
this.injectedMessage,
this.showDialog = false,
this.duration = const Duration(milliseconds: 2 * 800),
});

factory StateMessage.fromJson(Map<String, dynamic> json) =>
Expand All @@ -22,27 +23,31 @@ class StateMessage extends Equatable {
this.stringMessage,
this.injectedMessage,
this.showDialog = false,
this.duration = const Duration(milliseconds: 2 * 800),
}) : type = MessageType.error;

const StateMessage.warning({
this.messageHandler,
this.stringMessage,
this.injectedMessage,
this.showDialog = false,
this.duration = const Duration(milliseconds: 2 * 800),
}) : type = MessageType.warning;

const StateMessage.info({
this.messageHandler,
this.stringMessage,
this.injectedMessage,
this.showDialog = false,
this.duration = const Duration(milliseconds: 2 * 800),
}) : type = MessageType.info;

const StateMessage.success({
this.messageHandler,
this.stringMessage,
this.injectedMessage,
this.showDialog = false,
this.duration = const Duration(milliseconds: 2 * 800),
}) : type = MessageType.success;

final MessageType type;
Expand All @@ -51,10 +56,17 @@ class StateMessage extends Equatable {
final String? stringMessage;
final String? injectedMessage;
final bool showDialog;
final Duration duration;

Map<String, dynamic> toJson() => _$StateMessageToJson(this);

@override
List<Object?> get props =>
[type, messageHandler, stringMessage, injectedMessage, showDialog];
List<Object?> get props => [
type,
messageHandler,
stringMessage,
injectedMessage,
showDialog,
duration,
];
}
59 changes: 31 additions & 28 deletions lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
// ),
// ),
// );
} else if (state.uri.toString().startsWith('openid://?client_id') ||
state.uri.toString().startsWith('openid-vc://?client_id')) {
} else if (state.uri.toString().startsWith('openid://') ||
state.uri.toString().startsWith('openid-vc://')) {
/// ebsi v2 presentation
/// verifier side (siopv2) with request_uri
Expand Down Expand Up @@ -292,14 +292,17 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
ResponseString
.RESPONSE_STRING_pleaseSwitchToCorrectOIDC4VCProfile,
),
showDialog: true,
showDialog: false,
duration: const Duration(seconds: 20),
),
),
);
return;
}

if (!await isOIDC4VPAndSiopV2WithRequestURIValid(state.uri!)) {
final isRequestValid =
await isOIDC4VPAndSiopV2WithRequestURIValid(state.uri!);
if (!isRequestValid) {
emit(
state.copyWith(
qrScanStatus: QrScanStatus.success,
Expand Down Expand Up @@ -328,7 +331,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
ResponseString
.RESPONSE_STRING_pleaseSwitchToCorrectOIDC4VCProfile,
),
showDialog: true,
showDialog: false,
duration: const Duration(seconds: 20),
),
),
);
Expand Down Expand Up @@ -398,13 +402,13 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
return;
}

if (state.uri.toString().startsWith('openid://?client_id')) {
if (state.uri.toString().startsWith('openid://')) {
/// verifier side (OIDC4VP And siopv2) with request_uri
await launchOIDC4VPAndSiopV2WithRequestUriFlow(state.uri);
return;
}

if (state.uri.toString().startsWith('openid-vc://?client_id')) {
if (state.uri.toString().startsWith('openid-vc://')) {
/// verifier side (siopv2) with request_uri
await launchSiopV2WithRequestUriFlow(state.uri);
return;
Expand Down Expand Up @@ -831,24 +835,23 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}

Future<bool> isOIDC4VPAndSiopV2WithRequestURIValid(Uri uri) async {
bool isValid = true;

///credential should not be empty since we have to present
if (credentialsCubit.state.credentials.isEmpty) {
emitError(
ResponseMessage(ResponseString.RESPONSE_STRING_CREDENTIAL_EMPTY_ERROR),
);
isValid = false;
// emitError(
// ResponseMessage(ResponseString.RESPONSE_STRING_CREDENTIAL_EMPTY_ERROR),
// );

return false;
}

///request attribute check
if (requestAttributeExists(uri) && isValid) {
isValid = false;
emitError(
ResponseMessage(
ResponseString.RESPONSE_STRING_SCAN_UNSUPPORTED_MESSAGE,
),
);
if (requestAttributeExists(uri)) {
// emitError(
// ResponseMessage(
// ResponseString.RESPONSE_STRING_SCAN_UNSUPPORTED_MESSAGE,
// ),
// );
return false;
}

///request_uri attribute check
Expand All @@ -861,14 +864,14 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
final sIOPV2Param = await getSIOPV2Parameters(uri);

///check if claims exists
if (sIOPV2Param.claims == null && isValid) {
emitError(
ResponseMessage(
ResponseString.RESPONSE_STRING_SCAN_UNSUPPORTED_MESSAGE,
),
);
isValid = false;
if (sIOPV2Param.claims == null) {
// emitError(
// ResponseMessage(
// ResponseString.RESPONSE_STRING_SCAN_UNSUPPORTED_MESSAGE,
// ),
// );
return false;
}
return isValid;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class _QrCodeScanPageState extends State<QrCodeScanPage> {
listener: (context, state) async {
if (state.status == QrScanStatus.error) {
if (state.message != null) {
final Route<dynamic>? currentRoute = ModalRoute.of(context);
currentRoute!.didPop(true);
Navigator.of(context).pop();
}
}

Expand Down

0 comments on commit 66efe59

Please sign in to comment.