Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant display accent marks or "ñ" within Flutter

I have a backend built with Java and REST, and have this app in Android using Flutter, but there is an error when I am trying to display those characters.

for example instead of "Piña", the final work displays:

enter image description here

this is a part of the code where I am trying to use dart:convert, but not very succesful:

import 'dart:convert';

class ProductsProvider {
  Future<List<Product>> loadProducts(
      String urlMiddleware, Client client) async {
    final url = '$urlMiddleware${Constants().getProducts}${client.code}';
    final response = await http.get(url,
        headers: <String, String>{'authorization': Constants().basicAuth});
    print('Url');
    print(url);
    json.decode(utf8.decode(response.bodyBytes));
    final List<Product> products = productFromJson(response.body).toList();
    
    return products;
  }

This is my model btw:

import 'dart:convert';
import 'package:pil_store/models/EnumValues.dart';

List<Product> productFromJson(String str) => List<Product>.from(json.decode(utf8.decode(str.runes.toList())).map((x) => Product.fromJson(x)));

String productToJson(List<Product> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

I am not so old with this Flutter technology, how can I display the right character?

like image 526
Feber Castellon Avatar asked Nov 07 '25 08:11

Feber Castellon


1 Answers

I found the solution trying something different, just fyi:

class ProductsProvider {
  Future<List<Product>> loadProducts(
      String urlMiddleware, Client client) async {
    final url = '$urlMiddleware${Constants().getProducts}${client.code}';
    final response = await http.get(url,
        headers: <String, String>{'authorization': Constants().basicAuth});
    print('Url');
    print(url);
    final List<Product> products = productFromJson(Utf8Decoder().convert(response.bodyBytes)).toList();
    
    return products;
  }
like image 145
Feber Castellon Avatar answered Nov 10 '25 01:11

Feber Castellon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!