I'm using Flutter-web and I want to export a pdf. I'm using the pdf package and i'm trying to implement a simple example from their documentation. To be more specific, I have a file called export_pdf.dart and the code inside it is the following.
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
import 'package:universal_io/io.dart';
import 'package:path_provider/path_provider.dart';
exportPdf() async {
final pdf = Document();
pdf.addPage(Page(
pageFormat: PdfPageFormat.a4,
build: (Context context) {
return Center(
child: Text("Hello World"),
); // Center
})); // Page
final output = await getTemporaryDirectory();
final file = File("${output.path}/example.pdf");
await file.writeAsBytes(await pdf.save());
}
When i'm calling the exportPdf() function by clicking a button, i'm getting the following error.
Uncaught (in promise) Error: MissingPluginException(No implementation found for method getTemporaryDirectory on channel plugins.flutter.io/path_provider)
I've been searching for this issue for a long time, but no solution has fixed this one.
Even though the path_provider package is imported, the getTemporaryDirectory() is never called, like it doesn't exist.
I need also to mention that i'm using universal_io, instead of dart:io, because i'm using flutter_web.
This error shows up for every function i'm calling and exists inside the path_provider/path_provider.dart file. I've also added inside path_provider/path_provider.dart a simple print function and i'm getting an error that the method is not found.
Thank you for your time.