Skip to content

Commit

Permalink
Tune validation info strip UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej-Hlatky committed Nov 16, 2024
1 parent 1cc2d13 commit c69cc9e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 40 deletions.
8 changes: 7 additions & 1 deletion lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ abstract class AppLocalizations {
/// No description provided for @documentValidationNoSignaturesLabel.
///
/// In sk, this message translates to:
/// **'Dokument neobsahuje **žiadny podpis**'**
/// **'Dokument zatiaľ neobsahuje **žiadny podpis**'**
String get documentValidationNoSignaturesLabel;

/// No description provided for @documentValidationHasInvalidSignaturesLabel.
Expand All @@ -469,6 +469,12 @@ abstract class AppLocalizations {
/// **'Dokument obsahuje **neplatné podpisy**'**
String get documentValidationHasInvalidSignaturesLabel;

/// No description provided for @documentValidationHasIndeterminateSignatureLabel.
///
/// In sk, this message translates to:
/// **'Dokument obsahuje **neznámy podpis**'**
String get documentValidationHasIndeterminateSignatureLabel;

/// No description provided for @documentValidationHasValidSignaturesLabel.
///
/// In sk, this message translates to:
Expand Down
5 changes: 4 additions & 1 deletion lib/l10n/app_localizations_sk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,14 @@ class AppLocalizationsSk extends AppLocalizations {
String get documentValidationLoadingLabel => 'Prebieha overovanie podpisov';

@override
String get documentValidationNoSignaturesLabel => 'Dokument neobsahuje **žiadny podpis**';
String get documentValidationNoSignaturesLabel => 'Dokument zatiaľ neobsahuje **žiadny podpis**';

@override
String get documentValidationHasInvalidSignaturesLabel => 'Dokument obsahuje **neplatné podpisy**';

@override
String get documentValidationHasIndeterminateSignatureLabel => 'Dokument obsahuje **neznámy podpis**';

@override
String documentValidationHasValidSignaturesLabel(num count) {
String _temp0 = intl.Intl.pluralLogic(
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_sk.arb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@
"documentVisualizationCannotVisualizeTypeError": "Neviem vizualizovať {type} typ.",

"documentValidationLoadingLabel": "Prebieha overovanie podpisov",
"documentValidationNoSignaturesLabel": "Dokument neobsahuje **žiadny podpis**",
"documentValidationNoSignaturesLabel": "Dokument zatiaľ neobsahuje **žiadny podpis**",
"documentValidationHasInvalidSignaturesLabel": "Dokument obsahuje **neplatné podpisy**",
"documentValidationHasIndeterminateSignatureLabel": "Dokument obsahuje **neznámy podpis**",
"documentValidationHasValidSignaturesLabel": "{count, plural, one {Dokument obsahuje **1 podpis**} few {Dokument obsahuje **{count} podpisy**} many {Dokument obsahuje {count} podpisov**} other {Dokument obsahuje **{count} podpisov**}}",
"documentValidationSignaturesHeading": "Podpisy v dokumente",

Expand Down
22 changes: 16 additions & 6 deletions lib/ui/fragment/document_validation_fragment.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:autogram_sign/autogram_sign.dart'
show
DocumentValidationResponseBody,
DocumentValidationResponseBody$Signatures$Item,
DocumentValidationResponseBody$Signatures$ItemValidationResult;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -71,8 +72,9 @@ class _DocumentValidationFragmentState
),
DocumentValidationSuccessState state => DocumentValidationStrip(
value: DocumentValidationStripValue.value(
validCount: state.response.validSignaturesCount ?? 0,
invalidCount: state.response.invalidSignaturesCount ?? 0,
failedCount: state.response.failedCount,
indeterminateCount: state.response.indeterminateCount,
passedCount: state.response.passedCount,
),
onTap: () {
widget.onShowDocumentValidationInfoRequested.call(state.response);
Expand All @@ -87,10 +89,18 @@ class _DocumentValidationFragmentState
/// A set of extensions on [DocumentValidationResponseBody].
extension _DocumentValidationResponseBodyExtensions
on DocumentValidationResponseBody {
int? get validSignaturesCount => signatures
?.where((s) => s.validationResult == _ValidationResult.totalPassed)
List<DocumentValidationResponseBody$Signatures$Item> get signaturesOrEmpty =>
(signatures ?? []);

int get failedCount => signaturesOrEmpty
.where((s) => s.validationResult == _ValidationResult.totalFailed)
.length;

int get indeterminateCount => signaturesOrEmpty
.where((s) => s.validationResult == _ValidationResult.indeterminate)
.length;
int? get invalidSignaturesCount => signatures
?.where((s) => s.validationResult != _ValidationResult.totalPassed)

int get passedCount => signaturesOrEmpty
.where((s) => s.validationResult == _ValidationResult.totalPassed)
.length;
}
87 changes: 56 additions & 31 deletions lib/ui/widgets/document_validation_strip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,38 @@ class DocumentValidationStrip extends StatelessWidget {

@override
Widget build(BuildContext context) {
final data = (value.isLoading, value.validCount, value.invalidCount);
final data = (
value.isLoading,
value.failedCount,
value.indeterminateCount,
value.passedCount
);
final isLoading = value.isLoading;
final hasSignatures = (value.validCount > 0 || value.invalidCount > 0);

final hasSignatures =
(value.failedCount + value.indeterminateCount + value.passedCount) > 0;
final strings = context.strings;

final String text = switch (data) {
(true, _, _) => strings.documentValidationLoadingLabel,
(false, _, > 0) => strings.documentValidationHasInvalidSignaturesLabel,
(false, > 0, _) =>
strings.documentValidationHasValidSignaturesLabel(value.validCount),
(false, 0, 0) => strings.documentValidationNoSignaturesLabel,
(_, _, _) => "" // technically invalid case
};
final Color backgroundColor = switch (data) {
(true, _, _) => const Color(0xFF126DFF),
(false, _, > 0) => const Color(0xFFC3112B),
(false, > 0, _) => const Color(0xFF078814),
(false, 0, 0) => const Color(0xFF126DFF),
(_, _, _) => Colors.transparent,
final (String text, Color backgroundColor) = switch (data) {
(true, _, _, _) => (
strings.documentValidationLoadingLabel,
const Color(0xFF126DFF)
),
(false, 0, 0, 0) => (
strings.documentValidationNoSignaturesLabel,
const Color(0xFF126DFF),
),
(false, > 0, _, _) => (
strings.documentValidationHasInvalidSignaturesLabel,
const Color(0xFFC3112B),
),
(false, _, > 0, _) => (
strings.documentValidationHasIndeterminateSignatureLabel,
const Color(0xFFbd730c),
),
(false, 0, 0, > 0) => (
strings.documentValidationHasValidSignaturesLabel(value.passedCount),
const Color(0xFF078814),
),
(_, _, _, _) => ("", Colors.transparent), // technically invalid case
};
const foregroundColor = Colors.white;
final icon = (hasSignatures ? Icons.arrow_right_alt_outlined : Icons.close);
Expand Down Expand Up @@ -79,24 +91,31 @@ class DocumentValidationStrip extends StatelessWidget {
/// Value for [DocumentValidationStrip] widget.
class DocumentValidationStripValue {
final bool isLoading;
final int validCount;
final int invalidCount;
final int failedCount;
final int indeterminateCount;
final int passedCount;
final Object? error;

const DocumentValidationStripValue.loading()
: isLoading = true,
validCount = 0,
invalidCount = 0,
failedCount = 0,
indeterminateCount = 0,
passedCount = 0,
error = null;

const DocumentValidationStripValue.value({
required this.validCount,
required this.invalidCount,
required this.failedCount,
required this.indeterminateCount,
required this.passedCount,
}) : isLoading = false,
error = null;

const DocumentValidationStripValue.none()
: this.value(validCount: 0, invalidCount: 0);
: this.value(
failedCount: 0,
indeterminateCount: 0,
passedCount: 0,
);
}

@widgetbook.UseCase(
Expand All @@ -116,21 +135,27 @@ Widget previewLoadingDocumentValidationStrip(BuildContext context) {
type: DocumentValidationStrip,
)
Widget previewOtherDocumentValidationStrip(BuildContext context) {
final validCount = context.knobs.list(
label: 'Valid count',
final passedCount = context.knobs.list(
label: 'Passed count',
options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
initialOption: 0,
);
final indeterminateCount = context.knobs.list(
label: 'Indeterminate count',
options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
initialOption: 0,
);
final invalidCount = context.knobs.list(
label: 'Invalid count',
final failedCount = context.knobs.list(
label: 'Failed count',
options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
initialOption: 0,
);

return DocumentValidationStrip(
value: DocumentValidationStripValue.value(
validCount: validCount,
invalidCount: invalidCount,
failedCount: failedCount,
indeterminateCount: indeterminateCount,
passedCount: passedCount,
),
);
}

0 comments on commit c69cc9e

Please sign in to comment.