Skip to content

Commit

Permalink
Fix infinite loading state for remote signing
Browse files Browse the repository at this point in the history
  • Loading branch information
matejkepes committed Nov 17, 2024
1 parent 4d7687b commit e6e69ce
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 42 deletions.
19 changes: 13 additions & 6 deletions lib/bloc/present_signed_document_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';

import '../app_service.dart';
import '../data/document_signing_type.dart';
import '../file_extensions.dart';
import '../file_system_entity_extensions.dart';
import '../ui/screens/present_signed_document_screen.dart';
Expand All @@ -31,11 +32,17 @@ class PresentSignedDocumentCubit extends Cubit<PresentSignedDocumentState> {

final SignDocumentResponseBody signedDocument;

PresentSignedDocumentCubit({
required AppService appService,
@factoryParam required this.signedDocument,
}) : _appService = appService,
super(const PresentSignedDocumentInitialState());
PresentSignedDocumentCubit(
{required AppService appService,
@factoryParam required this.signedDocument,
@factoryParam required DocumentSigningType signingType})
: _appService = appService,
super(
signingType == DocumentSigningType.local
? const PresentSignedDocumentInitialState()
// Remote documents are not saved locally, so we go directly to success state
: const PresentSignedRemoteDocumentSuccessState(),
);

/// Saves [signedDocument] into public directory.
Future<void> saveDocument() async {
Expand Down Expand Up @@ -67,7 +74,7 @@ class PresentSignedDocumentCubit extends Cubit<PresentSignedDocumentState> {
Future<File> getShareableFile() async {
final state = this.state;

if (state is PresentSignedDocumentSuccessState) {
if (state is PresentSignedLocalDocumentSuccessState) {
final file = state.file;

if (await file.exists()) {
Expand Down
19 changes: 15 additions & 4 deletions lib/bloc/present_signed_document_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ sealed class PresentSignedDocumentState {
return PresentSignedDocumentErrorState(error);
}

PresentSignedDocumentSuccessState toSuccess(File file) {
return PresentSignedDocumentSuccessState(file);
PresentSignedLocalDocumentSuccessState toSuccess(File file) {
return PresentSignedLocalDocumentSuccessState(file);
}

@override
Expand Down Expand Up @@ -44,13 +44,24 @@ class PresentSignedDocumentErrorState extends PresentSignedDocumentState {
}
}

class PresentSignedDocumentSuccessState extends PresentSignedDocumentState {
class PresentSignedLocalDocumentSuccessState
extends PresentSignedDocumentState {
final File file;

const PresentSignedDocumentSuccessState(this.file);
const PresentSignedLocalDocumentSuccessState(this.file);

@override
String toString() {
return "$runtimeType(file: $file)";
}
}

class PresentSignedRemoteDocumentSuccessState
extends PresentSignedDocumentState {
const PresentSignedRemoteDocumentSuccessState();

@override
String toString() {
return "$runtimeType()";
}
}
62 changes: 32 additions & 30 deletions lib/di.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions lib/ui/screens/present_signed_document_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PresentSignedDocumentScreen extends StatelessWidget {
create: (context) {
final cubit = getIt.get<PresentSignedDocumentCubit>(
param1: signedDocument,
param2: signingType,
);

if (signingType == DocumentSigningType.local) {
Expand Down Expand Up @@ -163,11 +164,16 @@ class _Body extends StatelessWidget {
onShareFileRequested: onShareFileRequested,
onCloseRequested: onCloseRequested,
),
PresentSignedDocumentSuccessState state => _SuccessContent(
PresentSignedLocalDocumentSuccessState state => _SuccessContent(
file: state.file,
onShareFileRequested: onShareFileRequested,
onCloseRequested: onCloseRequested,
),
PresentSignedRemoteDocumentSuccessState() => _SuccessContent(
file: null,
onShareFileRequested: null,
onCloseRequested: onCloseRequested,
),
};
}
}
Expand Down Expand Up @@ -347,7 +353,7 @@ Widget previewSuccessPresentSignedDocumentScreen(BuildContext context) {
final file = File(path);

return _Body(
state: PresentSignedDocumentSuccessState(file),
state: PresentSignedLocalDocumentSuccessState(file),
signingType: signingType,
onShareFileRequested: () {
developer.log('onShareFileRequested');
Expand Down

0 comments on commit e6e69ce

Please sign in to comment.