Http响应正文中未显示阿拉伯字母-颤振

时间:2019-03-29 06:42:28

标签: dart flutter

我正在开发一个flutter应用程序,该应用程序使用带有阿拉伯字符的其余API,阿拉伯字符显示不佳。

http.get请求的代码:

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:

2 个答案:

答案 0 :(得分:4)

只需添加 (json.decode(utf8.decode(response.bodyBytes)))

代替json.decode(response.body)

这会将您的json解码为阿拉伯语

答案 1 :(得分:0)

当设备未安装字体时,可能会发生这种情况。

尝试在颤动中使用阿拉伯字体。

以下是指南:Custom Font Guideline Flutter