i am developing an flutter app that consume rest API with Arabic character, the Arabic character not showing well.

The code of http.get request:

Future<Null> fetchCustomers() {
    _isLoading = true;
    notifyListeners();
    return http.get('http://10.0.3.2:8000/transfers/', headers: {
      HttpHeaders.contentTypeHeader: 'application/json',
      HttpHeaders.acceptCharsetHeader:'utf-8', 
    }).then<Null>((http.Response response) {
      final List<Customer> fetchedCustomerList = [];
      var customerListData = json.decode(response.body);
      print(customerListData);
      print('here');
      final customerData =
          (customerListData as List).map((i) => new Customer.fromJson(i));
      print(customerData);
      print('before');
      if (customerListData == null) {
        _isLoading = false;
        notifyListeners();
        return;
      }
      customerListData.forEach((customerData) {
        final Customer customer = Customer(
          id: customerData['id'],
          name: customerData['name']
          mobile: customerData['mobile'],
          address: customerData['address'],
        );
        fetchedCustomerList.add(customer);
      });
      _customers = fetchedCustomerList;
      print(_customers);
      print("after");
      _isLoading = false;
      notifyListeners();
      _selCustomerId = null;
    }).catchError((error) {
      _isLoading = false;
      notifyListeners();
      return;
    });
  }

The character showing as below:


Solution 1: Mangaldeep Pannu

This can happen when device don't have the fonts installed.

Try using Arabic fonts in flutter.

Here is the guideline: Custom Font Guideline Flutter


Solution 2: ahmed elajnaf

just add (json.decode(utf8.decode(response.bodyBytes)))

instead of json.decode(response.body)

this will decode your json into arabic language


Solution 3: A.R.H

You need to tell your server what charterer set you expect from it by setting the accept header like below:

Future<Map<String, String>> getHeaders() {
  return <String, String>{
    'Content-Type': 'application/json; charset=UTF-8',
    'accept': 'application/json; charset=UTF-8',
  };
}

In the example above I'm telling the server that i will send and accept json in UTF-8 charterer set.

'Content-Type' for what I'm sending

'accept' for what I expect to receive