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
|
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||||
extensions:
|
extensions:
|
||||||
- provider: true
|
- 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> {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
action() => context.read<DocumentPageBloc>().add(UnselectDocumentEvent());
|
action() => context.read<DocumentPageBloc>().add(UnselectDocumentEvent());
|
||||||
|
|
||||||
final String title = widget.doc.description;
|
final String title = widget.doc.description;
|
||||||
final theme = FlutterFlowTheme.of(context);
|
final theme = FlutterFlowTheme.of(context);
|
||||||
return Scaffold(
|
return PopScope(
|
||||||
|
canPop: false,
|
||||||
|
onPopInvokedWithResult: (didPop, result) => action(),
|
||||||
|
child: Scaffold(
|
||||||
backgroundColor: theme.primaryBackground,
|
backgroundColor: theme.primaryBackground,
|
||||||
appBar: buildAppBar(title, context, action),
|
appBar: buildAppBar(title, context, action),
|
||||||
body: buildBody(context),
|
body: buildBody(context),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildBody(BuildContext context) {
|
Widget buildBody(BuildContext context) {
|
||||||
return Stack(
|
// final PDFViewerKey _viewerKey = PDFViewerKey();
|
||||||
children: [
|
|
||||||
Padding(
|
return PDFViewer(
|
||||||
padding: EdgeInsets.all(10),
|
// search: _viewerKey,
|
||||||
child: FREViewerPDF(
|
title: widget.doc.description,
|
||||||
search: _viewerKey,
|
url: widget.uri.toString(),
|
||||||
src: widget.uri.toString(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
bottom: 10,
|
|
||||||
right: 10,
|
|
||||||
child: IconButton(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.share,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
color: Colors.black,
|
|
||||||
onPressed: onShare,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import 'package:hub/shared/mixins/pegeable_mixin.dart';
|
||||||
import 'package:hub/shared/utils/index.dart';
|
import 'package:hub/shared/utils/index.dart';
|
||||||
import 'package:hub/shared/widgets/widgets.dart';
|
import 'package:hub/shared/widgets/widgets.dart';
|
||||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
||||||
part 'document_manager_screen.dart';
|
part 'document_manager_screen.dart';
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
part of '../widgets.dart';
|
part of '../widgets.dart';
|
||||||
|
|
||||||
typedef PDFViewerKey = GlobalKey<SfPdfViewerState>;
|
// typedef PDFViewerKey = GlobalKey<SfPdfViewerState>;
|
||||||
|
|
||||||
abstract interface class Viewer extends StatelessComponent {
|
abstract interface class Viewer extends StatelessComponent {
|
||||||
|
final String src;
|
||||||
|
|
||||||
const Viewer({
|
const Viewer({
|
||||||
super.key,
|
super.key,
|
||||||
required this.src,
|
required this.src,
|
||||||
});
|
});
|
||||||
final String src;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -17,25 +18,110 @@ abstract interface class Viewer extends StatelessComponent {
|
||||||
Widget buildViewer(BuildContext context);
|
Widget buildViewer(BuildContext context);
|
||||||
}
|
}
|
||||||
|
|
||||||
class FREViewerPDF extends StatelessComponent {
|
class PDFViewer extends StatefulWidget {
|
||||||
final String src;
|
final String url;
|
||||||
final PDFViewerKey search;
|
final String title;
|
||||||
|
|
||||||
const FREViewerPDF({
|
const PDFViewer({
|
||||||
super.key,
|
super.key,
|
||||||
required this.search,
|
required this.url,
|
||||||
required this.src,
|
required this.title,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
State<PDFViewer> createState() => PDFViewerState();
|
||||||
return buildViewer(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildViewer(BuildContext context) {
|
class PDFViewerState extends State<PDFViewer> {
|
||||||
return SfPdfViewer.network(
|
late PdfController _pdfController;
|
||||||
src,
|
|
||||||
key: search,
|
Future<PdfController> _initializePdf() async {
|
||||||
|
final file = await downloadPdf(widget.url);
|
||||||
|
final Future<PdfDocument> document = PdfDocument.openFile(file.path);
|
||||||
|
return PdfController(document: document);
|
||||||
|
}
|
||||||
|
|
||||||
|
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:developer';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:auto_size_text/auto_size_text.dart';
|
import 'package:auto_size_text/auto_size_text.dart';
|
||||||
import 'package:easy_debounce/easy_debounce.dart';
|
import 'package:easy_debounce/easy_debounce.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_fonts/google_fonts.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/features/documents/index.dart';
|
||||||
import 'package:hub/flutter_flow/index.dart';
|
import 'package:hub/flutter_flow/index.dart';
|
||||||
import 'package:hub/shared/mixins/pegeable_mixin.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: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 'page.dart';
|
||||||
part 'component.dart';
|
part 'component.dart';
|
||||||
|
|
|
@ -13,8 +13,8 @@ dependencies:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_localizations:
|
flutter_localizations:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
pdfx: ^2.8.0
|
||||||
auto_size_text: ^3.0.0
|
auto_size_text: ^3.0.0
|
||||||
syncfusion_flutter_pdfviewer: ^28.2.4
|
|
||||||
barcode_widget: ^2.0.4
|
barcode_widget: ^2.0.4
|
||||||
cached_network_image: ^3.4.0
|
cached_network_image: ^3.4.0
|
||||||
firebase_core: ^3.4.0
|
firebase_core: ^3.4.0
|
||||||
|
@ -25,7 +25,7 @@ dependencies:
|
||||||
app_links: ^6.3.2
|
app_links: ^6.3.2
|
||||||
# crop_your_image: 1.1.0
|
# crop_your_image: 1.1.0
|
||||||
csv: 6.0.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
|
firebase_messaging: ^15.1.0
|
||||||
dropdown_button2: 2.3.9
|
dropdown_button2: 2.3.9
|
||||||
easy_debounce: 2.0.3
|
easy_debounce: 2.0.3
|
||||||
|
|
Loading…
Reference in New Issue