Open Ayad-Ben-Saliem opened 10 months ago
Hi, you should try initialize your own font in main isolate and then pass this new font as parameter.
that will be something like:
void main async(){
// in main isolate
final font = await fontFromAssetBundle('assets/fonts/HacenTunisia/Regular.ttf');
Bill bill = Bill();
var result = Isolate.run(() async=> await createPdfBill(bill,font));
}
Future<Uint8List> createPdfBill(Bill bill, TtfFont font) async {
final pdf = Document();
pdf.addPage(
Page(build: (context) {
/* building a PDF here */
}),
);
return pdf.save();
}
@NurNur1 But while it works for the web, it should work for Android too. Your answer is great as a workaround solution, but I still think that there is a bug that needs to be fixed.
same problem happend for me, did you find any solution ?
Describe the bug I'm trying to create a PDF document on a separate isolate, and I use a custom font using
fontFromAssetBundle
method. its works fine for the web, but when I built an Android application I got the following exception:This is a sample of my code.
However, the code works fine on the web, but it didn't for the Android app.
Note 1- I added
WidgetsFlutterBinding.ensureInitialized();
inmain.dart
.2- I also tried to add
WidgetsFlutterBinding.ensureInitialized();
on the isolate, but I got another exceptionUI actions are only available on root isolate
.Is this a bug in
printing
? How to solve/workaround this issue?Now I execute
createBill
method in the main isolate to avoid this exception, but I hope this will be solved soon.Flutter Doctor
Build platforms
Build devices