impl pdfViewer release
This commit is contained in:
parent
263013930e
commit
2bb3312a39
|
@ -2,3 +2,4 @@ description: This file stores settings for Dart & Flutter DevTools.
|
|||
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||
extensions:
|
||||
- provider: true
|
||||
- patrol: true
|
Binary file not shown.
After Width: | Height: | Size: 73 KiB |
|
@ -15,55 +15,30 @@ class DocumentViewScreen extends StatefulScreen {
|
|||
}
|
||||
|
||||
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),
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) => action(),
|
||||
child: 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,
|
||||
),
|
||||
),
|
||||
],
|
||||
// final PDFViewerKey _viewerKey = PDFViewerKey();
|
||||
|
||||
return PDFViewer(
|
||||
// search: _viewerKey,
|
||||
title: widget.doc.description,
|
||||
url: widget.uri.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import 'package:hub/shared/mixins/pegeable_mixin.dart';
|
|||
import 'package:hub/shared/utils/index.dart';
|
||||
import 'package:hub/shared/widgets/widgets.dart';
|
||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
part 'document_manager_screen.dart';
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
part of '../widgets.dart';
|
||||
|
||||
typedef PDFViewerKey = GlobalKey<SfPdfViewerState>;
|
||||
// typedef PDFViewerKey = GlobalKey<SfPdfViewerState>;
|
||||
|
||||
abstract interface class Viewer extends StatelessComponent {
|
||||
final String src;
|
||||
|
||||
const Viewer({
|
||||
super.key,
|
||||
required this.src,
|
||||
});
|
||||
final String src;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -17,25 +18,110 @@ abstract interface class Viewer extends StatelessComponent {
|
|||
Widget buildViewer(BuildContext context);
|
||||
}
|
||||
|
||||
class FREViewerPDF extends StatelessComponent {
|
||||
final String src;
|
||||
final PDFViewerKey search;
|
||||
class PDFViewer extends StatefulWidget {
|
||||
final String url;
|
||||
final String title;
|
||||
|
||||
const FREViewerPDF({
|
||||
const PDFViewer({
|
||||
super.key,
|
||||
required this.search,
|
||||
required this.src,
|
||||
required this.url,
|
||||
required this.title,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return buildViewer(context);
|
||||
State<PDFViewer> createState() => PDFViewerState();
|
||||
}
|
||||
|
||||
class PDFViewerState extends State<PDFViewer> {
|
||||
late PdfController _pdfController;
|
||||
|
||||
Future<PdfController> _initializePdf() async {
|
||||
final file = await downloadPdf(widget.url);
|
||||
final Future<PdfDocument> document = PdfDocument.openFile(file.path);
|
||||
return PdfController(document: document);
|
||||
}
|
||||
|
||||
Widget buildViewer(BuildContext context) {
|
||||
return SfPdfViewer.network(
|
||||
src,
|
||||
key: search,
|
||||
Future<File> downloadPdf(String url) async {
|
||||
final response = await http.get(Uri.parse(url));
|
||||
if (response.statusCode == 200) {
|
||||
final bytes = response.bodyBytes;
|
||||
final dir = await getTemporaryDirectory();
|
||||
final file = File('${dir.path}/downloaded.pdf');
|
||||
await file.writeAsBytes(bytes);
|
||||
return file;
|
||||
} else {
|
||||
throw Exception('Falha ao baixar o PDF');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: [
|
||||
_buildPDFViewer(),
|
||||
buildShareButton(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Positioned buildShareButton() {
|
||||
return Positioned(
|
||||
bottom: 10,
|
||||
right: 10,
|
||||
child: IconButton(
|
||||
icon: Icon(
|
||||
Icons.share,
|
||||
color: Colors.black,
|
||||
),
|
||||
color: Colors.black,
|
||||
onPressed: onShare,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void onShare() async {
|
||||
final Uri uri = Uri.parse(widget.url);
|
||||
final response = await http.get(uri);
|
||||
if (response.statusCode == 200) {
|
||||
final XFile xfile = XFile.fromData(response.bodyBytes,
|
||||
name: '${widget.title}.pdf', mimeType: 'application/pdf');
|
||||
await Share.shareXFiles([xfile], text: 'Confira este PDF!');
|
||||
} else {
|
||||
print('Erro ao baixar o arquivo: ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildLoadingIndicator(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 15),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
FlutterFlowTheme.of(context).primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPDFViewer() => Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: FutureBuilder<PdfController>(
|
||||
future: _initializePdf(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) return buildLoadingIndicator(context);
|
||||
return PdfView(
|
||||
controller: snapshot.data!,
|
||||
scrollDirection: Axis.vertical,
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
// Widget get progressIndicator => LoadingUtil.buildLoadingIndicator(context);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pdfController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:auto_size_text/auto_size_text.dart';
|
||||
import 'package:easy_debounce/easy_debounce.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:hub/features/documents/index.dart';
|
||||
import 'package:hub/flutter_flow/index.dart';
|
||||
import 'package:hub/shared/mixins/pegeable_mixin.dart';
|
||||
import 'package:hub/shared/utils/index.dart';
|
||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdfx/pdfx.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
part 'page.dart';
|
||||
part 'component.dart';
|
||||
|
|
|
@ -13,8 +13,8 @@ dependencies:
|
|||
sdk: flutter
|
||||
flutter_localizations:
|
||||
sdk: flutter
|
||||
pdfx: ^2.8.0
|
||||
auto_size_text: ^3.0.0
|
||||
syncfusion_flutter_pdfviewer: ^28.2.4
|
||||
barcode_widget: ^2.0.4
|
||||
cached_network_image: ^3.4.0
|
||||
firebase_core: ^3.4.0
|
||||
|
@ -25,7 +25,7 @@ dependencies:
|
|||
app_links: ^6.3.2
|
||||
# crop_your_image: 1.1.0
|
||||
csv: 6.0.0
|
||||
device_info_plus: ^11.2.2
|
||||
device_info_plus: ^10.1.2 #11.2.2
|
||||
firebase_messaging: ^15.1.0
|
||||
dropdown_button2: 2.3.9
|
||||
easy_debounce: 2.0.3
|
||||
|
|
Loading…
Reference in New Issue