When I call the createPDF function nothing happens. I use my phone as emulator and its Android.
This is the code:
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';
import 'package:pdf/widgets.dart' as pw ;
class PdfView {
PdfView();
static void createPDF()async {
String path = (await getApplicationDocumentsDirectory()).path;
File file = File('${path}my_resume.pdf');
final font = await rootBundle.load("assets/fonts/Poppins/Poppins-Italic.ttf");
final ttf = pw.Font.ttf(font);
final pdf = pw.Document();
pdf.addPage(_addPage(font :ttf,size: 50));
Uint8List bytes = await pdf.save();
await file.writeAsBytes(bytes);
await OpenFile.open(file.path);
}
static pw.Page _addPage({required pw.Font font,required double size}){
pw.TextStyle? style= pw.TextStyle(font: font,fontSize: size);
return pw.Page(
build: (pw.Context context) {
return pw.Center(
child: pw.Text('Hello World!',style: style),
);
});
}
}
I tried make the createPDF function future and async onpressed of the button that after press on it the PDF created but also nothing happened.
This solution works for both android and iOS - please follow me on instagram - https://www.instagram.com/mcbflutter/
took it a step further and even made a table to show a few features...
add a custom file for the table
configuration for iOS
add these two keys to your info.plist
for android - Configure your android manifest
essentially it will look like this - lines 2 and 36 to 46
result: