Reputation: 3
I want to open or download a PDF-File inside my webview. I tried to enableFilesURl inside the webview community version but it doesn´t work.
Best regards Falk
Upvotes: 0
Views: 4306
Reputation: 1580
Future<File> createFileOfPdfUrl({String urlP = ''}) async {
final url = urlP;
String filename = '${DateTime.now().microsecondsSinceEpoch}';
var request = await HttpClient()?.getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$filename');
await file.writeAsBytes(bytes);
return file;
}
. .
createFileOfPdfUrl(urlP: '${jsonRes['m']}').then((res) {
Navigator.push(context, MaterialPageRoute(builder: (context) => PDFScreen(res.path)));
});
. . .
class PDFScreen extends StatelessWidget {
String pathPDF = "";
PDFScreen(this.pathPDF);
@override
Widget build(BuildContext context) {
return PDFViewerScaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(Icons.arrow_back_ios),
),
centerTitle: true,
title: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"PDF",
style: TextStyle(
fontSize: 16,
color: Theme.of(context).accentColor,
),
),
Text("Önizleme", style: TextStyle(color: Theme.of(context).accentTextTheme.subtitle.color, fontSize: 14)),
],
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.share),
onPressed: () {
Share.share('$pathPDF');
},
),
],
),
path: pathPDF);
}
}
Upvotes: 1