Skip to content
New issue

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

The PDF Showing Platform Exception error on Mobile Devices but Perfectly working on Web #553

Open
Ramya3322 opened this issue Jan 20, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Ramya3322
Copy link

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

@Ramya3322 Ramya3322 added the bug Something isn't working label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants