Add session token handling for PDF viewer in DocumentViewerModal and DocumentViewer
This commit is contained in:
@@ -4,6 +4,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../blocs/document_viewer/document_viewer_bloc.dart';
|
||||
import '../blocs/document_viewer/document_viewer_event.dart';
|
||||
import '../blocs/document_viewer/document_viewer_state.dart';
|
||||
import '../blocs/session/session_bloc.dart';
|
||||
import '../blocs/session/session_state.dart';
|
||||
import '../services/file_service.dart';
|
||||
import '../injection.dart';
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
@@ -167,7 +169,20 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
}
|
||||
if (state is DocumentViewerReady) {
|
||||
if (state.caps.isPdf) {
|
||||
return SfPdfViewer.network(state.viewUrl.toString());
|
||||
return BlocBuilder<SessionBloc, SessionState>(
|
||||
builder: (context, sessionState) {
|
||||
String? token;
|
||||
if (sessionState is SessionActive) {
|
||||
token = sessionState.token;
|
||||
}
|
||||
return SfPdfViewer.network(
|
||||
state.viewUrl.toString(),
|
||||
headers: token != null
|
||||
? {'Authorization': 'Bearer $token'}
|
||||
: {},
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Container(
|
||||
color: AppTheme.secondaryText,
|
||||
@@ -318,8 +333,20 @@ class _DocumentViewerState extends State<DocumentViewer> {
|
||||
}
|
||||
if (state is DocumentViewerReady) {
|
||||
if (state.caps.isPdf) {
|
||||
// Use PDF viewer
|
||||
return SfPdfViewer.network(state.viewUrl.toString());
|
||||
return BlocBuilder<SessionBloc, SessionState>(
|
||||
builder: (context, sessionState) {
|
||||
String? token;
|
||||
if (sessionState is SessionActive) {
|
||||
token = sessionState.token;
|
||||
}
|
||||
return SfPdfViewer.network(
|
||||
state.viewUrl.toString(),
|
||||
headers: token != null
|
||||
? {'Authorization': 'Bearer $token'}
|
||||
: {},
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// Placeholder for office docs iframe
|
||||
return Container(
|
||||
|
||||
Reference in New Issue
Block a user