70 lines
1.8 KiB
Dart
70 lines
1.8 KiB
Dart
part of 'index.dart';
|
|
|
|
class DocumentViewScreen extends StatefulScreen {
|
|
const DocumentViewScreen({
|
|
super.key,
|
|
required this.doc,
|
|
required this.uri,
|
|
});
|
|
|
|
final Document doc;
|
|
final Uri uri;
|
|
|
|
@override
|
|
ScreenState<DocumentViewScreen> createState() => _DocumentViewScreenState();
|
|
}
|
|
|
|
class _DocumentViewScreenState extends ScreenState<DocumentViewScreen> {
|
|
final PDFViewerKey _viewerKey = PDFViewerKey();
|
|
|
|
void onShare() async {
|
|
final response = await http.get(widget.uri);
|
|
if (response.statusCode == 200) {
|
|
final XFile xfile = XFile.fromData(response.bodyBytes,
|
|
name: '${widget.doc.description}.pdf', mimeType: 'application/pdf');
|
|
await Share.shareXFiles([xfile], text: 'Confira este PDF!');
|
|
} else {
|
|
print('Erro ao baixar o arquivo: ${response.statusCode}');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
action() => context.read<DocumentPageBloc>().add(UnselectDocumentEvent());
|
|
|
|
final String title = widget.doc.description;
|
|
final theme = FlutterFlowTheme.of(context);
|
|
return Scaffold(
|
|
backgroundColor: theme.primaryBackground,
|
|
appBar: buildAppBar(title, context, action),
|
|
body: buildBody(context),
|
|
);
|
|
}
|
|
|
|
Widget buildBody(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.all(10),
|
|
child: FREViewerPDF(
|
|
search: _viewerKey,
|
|
src: widget.uri.toString(),
|
|
),
|
|
),
|
|
Positioned(
|
|
bottom: 10,
|
|
right: 10,
|
|
child: IconButton(
|
|
icon: Icon(
|
|
Icons.share,
|
|
color: Colors.black,
|
|
),
|
|
color: Colors.black,
|
|
onPressed: onShare,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|