We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HERE IS MY FULL CODE
//For showing the pdf ui
class PdfViewerScreen extends StatefulWidget { final String pdfUrl; final int targetPage;
PdfViewerScreen({ required this.pdfUrl, required this.targetPage, });
@OverRide State createState() => _PdfViewerScreenState(); }
class _PdfViewerScreenState extends State { late PdfControllerPinch pdfControllerPinch; int totalPages = 0; int currentPage = 1;
@OverRide void initState() { super.initState(); _initializePdfController(); }
void _initializePdfController() { pdfControllerPinch = PdfControllerPinch( document: PdfDocument.openAsset(widget.pdfUrl), initialPage: widget.targetPage, ); }
@OverRide void didUpdateWidget(covariant PdfViewerScreen oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.pdfUrl != widget.pdfUrl) { pdfControllerPinch.dispose(); _initializePdfController(); } else if (oldWidget.targetPage != widget.targetPage) { pdfControllerPinch.animateToPage( pageNumber: widget.targetPage, duration: Duration(milliseconds: 500), curve: Curves.easeInOut, ); } }
@OverRide void dispose() { pdfControllerPinch.dispose(); super.dispose(); }
@OverRide Widget build(BuildContext context) { return Scaffold( body: Column( children: [ _PageControls(), SizedBox( height: 20, ), Expanded(child: _PdfView()), ], ), ); }
Widget _PdfView() { return PdfViewPinch( controller: pdfControllerPinch, onDocumentLoaded: (document) { if (mounted) { setState(() { totalPages = document.pagesCount; }); } }, onPageChanged: (page) { if (mounted) { setState(() { currentPage = page; }); } }, ); }
Widget _PageControls() { return Row( mainAxisAlignment: Get.width < 600 ? MainAxisAlignment.spaceBetween : MainAxisAlignment.center, children: [ if (Get.width < 600) Row( children: [ IconButton( icon: Icon( Icons.arrow_back, size: 22, ), onPressed: () { appController.isVibrationEnabled.value ? Vibrate.feedback(FeedbackType.success) : null; Get.back(); }), ], ), Row( children: [ IconButton( onPressed: () { if (currentPage > 1) { pdfControllerPinch.previousPage( duration: Duration(milliseconds: 500), curve: Curves.easeIn, ); } }, icon: Icon( Icons.arrow_back, color: Theme.of(context).primaryColor, )), Text( '$currentPage / $totalPages', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), IconButton( onPressed: () { if (currentPage < totalPages) { pdfControllerPinch.nextPage( duration: Duration(milliseconds: 500), curve: Curves.easeOut, ); } }, icon: Icon( Icons.arrow_forward, color: Theme.of(context).primaryColor, )), ], ) ], ); } }
//Navigation to pdf
SizedBox( width: double.infinity, height: 1200, child: PdfViewerScreen( pdfUrl: 'assets/pdfs/Sample CV-.docx.pdf', targetPage: targetPage, ), ),
REMINDERI have tried different pdfs still the same issue on mobile devices
The text was updated successfully, but these errors were encountered:
SergeShkurko
No branches or pull requests
HERE IS MY FULL CODE
//For showing the pdf ui
class PdfViewerScreen extends StatefulWidget {
final String pdfUrl;
final int targetPage;
PdfViewerScreen({
required this.pdfUrl,
required this.targetPage,
});
@OverRide
State createState() => _PdfViewerScreenState();
}
class _PdfViewerScreenState extends State {
late PdfControllerPinch pdfControllerPinch;
int totalPages = 0;
int currentPage = 1;
@OverRide
void initState() {
super.initState();
_initializePdfController();
}
void _initializePdfController() {
pdfControllerPinch = PdfControllerPinch(
document: PdfDocument.openAsset(widget.pdfUrl),
initialPage: widget.targetPage,
);
}
@OverRide
void didUpdateWidget(covariant PdfViewerScreen oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.pdfUrl != widget.pdfUrl) {
pdfControllerPinch.dispose();
_initializePdfController();
} else if (oldWidget.targetPage != widget.targetPage) {
pdfControllerPinch.animateToPage(
pageNumber: widget.targetPage,
duration: Duration(milliseconds: 500),
curve: Curves.easeInOut,
);
}
}
@OverRide
void dispose() {
pdfControllerPinch.dispose();
super.dispose();
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
_PageControls(),
SizedBox(
height: 20,
),
Expanded(child: _PdfView()),
],
),
);
}
Widget _PdfView() {
return PdfViewPinch(
controller: pdfControllerPinch,
onDocumentLoaded: (document) {
if (mounted) {
setState(() {
totalPages = document.pagesCount;
});
}
},
onPageChanged: (page) {
if (mounted) {
setState(() {
currentPage = page;
});
}
},
);
}
Widget _PageControls() {
return Row(
mainAxisAlignment: Get.width < 600
? MainAxisAlignment.spaceBetween
: MainAxisAlignment.center,
children: [
if (Get.width < 600)
Row(
children: [
IconButton(
icon: Icon(
Icons.arrow_back,
size: 22,
),
onPressed: () {
appController.isVibrationEnabled.value
? Vibrate.feedback(FeedbackType.success)
: null;
Get.back();
}),
],
),
Row(
children: [
IconButton(
onPressed: () {
if (currentPage > 1) {
pdfControllerPinch.previousPage(
duration: Duration(milliseconds: 500),
curve: Curves.easeIn,
);
}
},
icon: Icon(
Icons.arrow_back,
color: Theme.of(context).primaryColor,
)),
Text(
'$currentPage / $totalPages',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
IconButton(
onPressed: () {
if (currentPage < totalPages) {
pdfControllerPinch.nextPage(
duration: Duration(milliseconds: 500),
curve: Curves.easeOut,
);
}
},
icon: Icon(
Icons.arrow_forward,
color: Theme.of(context).primaryColor,
)),
],
)
],
);
}
}
//Navigation to pdf
SizedBox(
width: double.infinity,
height: 1200,
child: PdfViewerScreen(
pdfUrl: 'assets/pdfs/Sample CV-.docx.pdf',
targetPage: targetPage,
),
),
REMINDERI have tried different pdfs still the same issue on mobile devices
The text was updated successfully, but these errors were encountered: