-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview_document_cubit.dart
47 lines (36 loc) · 1.45 KB
/
preview_document_cubit.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import 'package:autogram_sign/autogram_sign.dart';
import 'package:flutter_bloc/flutter_bloc.dart' show Cubit;
import 'package:injectable/injectable.dart';
import 'package:logging/logging.dart';
import '../ui/screens/preview_document_screen.dart';
import 'create_document_cubit.dart';
import 'preview_document_state.dart';
export 'preview_document_state.dart';
/// Cubit for the [PreviewDocumentScreen] with only [getVisualization] function.
///
/// See also:
/// - [CreateDocumentCubit]
@injectable
class PreviewDocumentCubit extends Cubit<PreviewDocumentState> {
static final _log = Logger((PreviewDocumentCubit).toString());
final IAutogramService _service;
final String documentId;
PreviewDocumentCubit({
required IAutogramService service,
@factoryParam required this.documentId,
}) : _service = service,
super(const PreviewDocumentInitialState());
/// Gets the Document Visualisation for [documentId].
Future<void> getVisualization() async {
emit(state.toLoading());
try {
_log.info("Getting Document Visualisation for Document Id: $documentId");
final visualization = await _service.getDocumentVisualization(documentId);
_log.info("Got Document Visualisation.");
emit(state.toSuccess(visualization));
} catch (error, stackTrace) {
_log.severe("Error getting Document Visualisation.", error, stackTrace);
emit(state.toError(error));
}
}
}