Skip to content

Commit

Permalink
Merge branch 'main' into texts-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
celuchmarek committed Jun 14, 2024
2 parents 72092ad + fc6544e commit 38c7b99
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## 2024-06-13 - v1.0.0(29)

- Fix Signature Type setting UX

## 2024-06-13 - v1.0.0(28)

Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/get_document_signature_type_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GetDocumentSignatureTypeCubit
super(const GetDocumentSignatureTypeInitialState());

/// Sets the [signatureType] directly.
void setSignatureType(SignatureType signatureType) {
void setSignatureType(SignatureType? signatureType) {
emit(GetDocumentSignatureTypeSuccessState(signatureType));
}

Expand Down
36 changes: 30 additions & 6 deletions lib/ui/screens/select_certificate_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ class _Body extends StatelessWidget {
}
}

/// Success content where [Certificate] was loaded.
/// Only thing is to determine [SignatureType] for given Document, either when:
/// - [DocumentSigningType.local] - from [ISettings.signatureType]
/// - [DocumentSigningType.remote] - by calling [GetDocumentSignatureTypeCubit.getDocumentSignatureType]
///
/// Uses [GetDocumentSignatureTypeCubit].
///
/// Consumes [ISettings].
class _SelectSignatureTypeContent extends StatefulWidget {
final String? subject;
final DocumentSigningType signingType;
Expand All @@ -175,6 +183,15 @@ class _SelectSignatureTypeContentState
extends State<_SelectSignatureTypeContent> {
SignatureType? _signatureType;

@override
void initState() {
super.initState();

if (widget.signingType == DocumentSigningType.local) {
_signatureType = context.read<ISettings>().signatureType.value;
}
}

@override
Widget build(BuildContext context) {
final strings = context.strings;
Expand All @@ -183,10 +200,10 @@ class _SelectSignatureTypeContentState
final cubit = getIt.get<GetDocumentSignatureTypeCubit>();

switch (widget.signingType) {
// TODO Refactor this flow; Need to work with Settings in cubit ctor
// And refactor this widget to be Stateful and work only with Cubit state
case DocumentSigningType.local:
cubit.setSignatureType(
context.read<ISettings>().signatureType.value,
);
cubit.setSignatureType(_signatureType);
break;

case DocumentSigningType.remote:
Expand All @@ -196,8 +213,16 @@ class _SelectSignatureTypeContentState

return cubit;
},
child: BlocBuilder<GetDocumentSignatureTypeCubit,
child: BlocConsumer<GetDocumentSignatureTypeCubit,
GetDocumentSignatureTypeState>(
listener: (context, state) {
if (state is GetDocumentSignatureTypeSuccessState) {
setState(() {
_signatureType =
(state.signatureType ?? SignatureType.withoutTimestamp);
});
}
},
builder: (context, state) {
return switch (state) {
GetDocumentSignatureTypeInitialState _ => const LoadingContent(),
Expand All @@ -207,8 +232,7 @@ class _SelectSignatureTypeContentState
error: state.error,
),
GetDocumentSignatureTypeSuccessState state => SignatureTypePicker(
value: _signatureType ??
(state.signatureType ?? SignatureType.withoutTimestamp),
value: _signatureType,
canChange: (widget.signingType == DocumentSigningType.local),
onValueChanged: (final SignatureType value) {
setState(() {
Expand Down
6 changes: 5 additions & 1 deletion lib/ui/screens/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ class _Body extends StatelessWidget {

final signatureType = _ValueListenableBoundTile<SignatureType>(
setting: settings.signatureType,
values: SignatureType.values,
values: const [
SignatureType.unset,
SignatureType.withTimestamp,
SignatureType.withoutTimestamp,
],
title: strings.signatureTypeTitle,
summaryGetter: (value) => strings.signatureTypeSummary(value.name),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: autogram
description: "Autogram v mobile"
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+28
version: 1.0.0+29

environment:
sdk: '>=3.2.3 <4.0.0'
Expand Down

0 comments on commit 38c7b99

Please sign in to comment.