I am using PDF VIEWER and fetching Google Drive Pdf but it is showing Ranger Error. It was working fine earlier but all of a sudden it is giving me this error of Range Error. I tried different URL and it is working but using google drive pdf it is not working. Earlier it used to work as other links.
import 'package:flutter/material.dart';
import 'package:advance_pdf_viewer2/advance_pdf_viewer.dart';
class FmtCH11 extends StatefulWidget {
@override
_GeneralState createState() => _GeneralState();
}
class _GeneralState extends State<FmtCH11> {
bool _isLoading = true;
late PDFDocument _doc;
String url =
"https://drive.google.com/uc?export=download&id=1oqzz9m6IcJFpXuMWWnvkXYfXPlpfEOBo";
void initState() {
super.initState();
_initPdf();
}
_initPdf() async {
setState(() {
_isLoading = true;
});
final doc = await PDFDocument.fromURL(url);
setState(() {
_doc = doc;
_isLoading = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Introduction"),
),
body: _isLoading
? Center(
child: CircularProgressIndicator(),
)
: PDFViewer(
document: _doc,
));
}
}
It is showing error -
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0
#0 _Array.[] (dart:core-patch/array.dart:10:36)
#1 _PDFViewerState._loadPage
viewer.dart:149
#2 _PDFViewerState.didChangeDependencies
viewer.dart:125
#3 StatefulElement._firstBuild
framework.dart:5237
#4 ComponentElement.mount
framework.dart:5062
#5 Element.inflateWidget
framework.dart:3971
#6 Element.updateChild
framework.dart:3702
#7 ComponentElement.performRebuild
framework.dart:5111
#8 Element.rebuild
framework.dart:4805
#9 StatelessElement.update
framework.dart:5162
#10 Element.updateChild (package:flutter/src/widgets/framew<…>
Really Grateful if you help, a little URGERNT
your FmtCH11 does not give index error it comes from somewhere else
You can not directly view google drive pdf link these are 2 options :
Show it in web view https://stackoverflow.com/a/60599478/6656661
or
Download in document directory of application then show
https://www.syncfusion.com/forums/176887/how-to-load-pdfs-host-with-google-drive-or-dropbox