Skip to content

Commit

Permalink
feat: Update json viewer page
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Oct 20, 2023
1 parent 02363d2 commit aae98f9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
22 changes: 11 additions & 11 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1027,20 +1027,20 @@ String getFormattedStringOIDC4VCI({
dynamic credentialOfferJson,
}) {
return '''
SCHEME : ${getSchemeFromUrl(url)}\n
CREDENTIAL OFFER :
<b>SCHEME :</b> ${getSchemeFromUrl(url)}\n
<b>CREDENTIAL OFFER :</b>
${credentialOfferJson != null ? const JsonEncoder.withIndent(' ').convert(credentialOfferJson) : 'None'}\n
ENDPOINTS :
<b>ENDPOINTS :</b>
authorization server endpoint : ${openidConfigurationResponse?['authorization_server'] ?? 'None'}
token endpoint : ${openidConfigurationResponse?['token_endpoint'] ?? authorizationServerConfiguration?['token_endpoint'] ?? 'None'}
credential endpoint : ${openidConfigurationResponse?['credential_endpoint'] ?? 'None'}
deferred endpoint : ${openidConfigurationResponse?['deferred_endpoint'] ?? 'None'}
batch endpoint : ${openidConfigurationResponse?['batch_endpoint'] ?? 'None'}\n
CREDENTIAL SUPPORTED :
<b>CREDENTIAL SUPPORTED :</b>
${openidConfigurationResponse?['credentials_supported'] != null ? const JsonEncoder.withIndent(' ').convert(openidConfigurationResponse!['credentials_supported']) : 'None'}\n
AUTHORIZATION SERVER CONFIGURATION :
<b>AUTHORIZATION SERVER CONFIGURATION :</b>
${authorizationServerConfiguration != null ? const JsonEncoder.withIndent(' ').convert(authorizationServerConfiguration) : 'None'}\n
CRDENTIAL ISSUER CONFIGURATION :
<b>CRDENTIAL ISSUER CONFIGURATION :</b>
${openidConfigurationResponse != null ? const JsonEncoder.withIndent(' ').convert(openidConfigurationResponse) : 'None'}
''';
}
Expand Down Expand Up @@ -1068,14 +1068,14 @@ Future<String> getFormattedStringOIDC4VPSIOPV2({
: null;

final data = '''
SCHEME : ${getSchemeFromUrl(url)}\n
AUTHORIZATION REQUEST :
<b>SCHEME :</b> ${getSchemeFromUrl(url)}\n
<b>AUTHORIZATION REQUEST :</b>
${response != null ? const JsonEncoder.withIndent(' ').convert(response) : 'None'}\n
CLIENT METADATA :
<b>CLIENT METADATA :</b>
${clientMetaData != null ? const JsonEncoder.withIndent(' ').convert(clientMetaData) : 'None'}\n
PRESENTATION DEFINITION :
PRESENTATION DEFINITION :</b>
${presentationDefinition != null ? const JsonEncoder.withIndent(' ').convert(presentationDefinition) : 'None'}\n
REGISTRATION :
<b>REGISTRATION :</b>
${registrationMap != null ? const JsonEncoder.withIndent(' ').convert(registrationMap) : 'None'}
''';

Expand Down
36 changes: 33 additions & 3 deletions lib/dashboard/json_viewer/view/json_viewer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,45 @@ class JsonViewerView extends StatelessWidget {

@override
Widget build(BuildContext context) {
final pattern = RegExp(r'<b>(.*?)<\/b>');
final matches = pattern.allMatches(data);

final textSpans = <TextSpan>[];
int currentIndex = 0;

for (final match in matches) {
final plainText = data.substring(currentIndex, match.start);
final boldText = data.substring(match.start + 3, match.end - 4);
textSpans.add(
TextSpan(
text: plainText,
style: Theme.of(context).textTheme.bodyMedium,
),
);
textSpans.add(
TextSpan(
text: boldText,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
fontWeight: FontWeight.w700,
),
),
);
currentIndex = match.end;
}

if (currentIndex < data.length) {
final remainingText = data.substring(currentIndex);
textSpans.add(TextSpan(text: remainingText));
}

return BasePage(
title: title,
titleAlignment: Alignment.topCenter,
scrollView: true,
titleLeading: const BackLeadingButton(),
padding: const EdgeInsets.symmetric(horizontal: 10),
body: Text(
data,
style: Theme.of(context).textTheme.bodyMedium,
body: RichText(
text: TextSpan(children: textSpans),
),
);
}
Expand Down

0 comments on commit aae98f9

Please sign in to comment.