Search code examples
flutterutf-8decodeencodearabic

Flutter: Arabic language isn't recognizable, it seems like symbols, and want to encode/decode


I have a text wanna show it in pdf file created by Flutter app

The English letters shown ok, but the Arabic has problems with appearing!!!

I used 'dart:convert' package for edcoding/decoding from utf-8, but there is a mistake I didn't know it.

This is the code:

onPress: () async {
                  var encoded1 = utf8.encode(firstName);
                  var encoded2 = utf8.encode(lastName);
                  var decoded1 = utf8.decode(encoded1);
                  var decoded2 = utf8.decode(encoded2);
                  final data = await controller.createInvoice(
                    items: controller.items,
                    firstName: encoded1.toString(),
                    lastName: decoded2,
                    counterNumber: counterNo,
                    subType: subType,
                    date: controller.date,
                  );
                  controller.savePdfFile('invoice_5', data);
                },

Here in my code, at firstName I used encode, and in the lastName I used decode to see what is the difference, but still have problem with both like what shown in the attached image.

This is the result: enter image description here


Solution

  • Finally I solve this problem, It's related to the font family

    Once I changed many fonts (support Arabic lang) and tried them, One of them accepted.