How can I convert string to utf8 in Dart?

前端 未结 2 621
时光取名叫无心
时光取名叫无心 2020-12-17 17:17

I am using aqueduct web api framework to support my flutter app. In my api backend I need to connect local network socket services. My problem is that I can\'t return the ex

相关标签:
2条回答
  • 2020-12-17 17:50
    import 'dart:convert' show utf8;
    
    var encoded = utf8.encode('Lorem ipsum dolor sit amet, consetetur...');
    var decoded = utf8.decode(encoded);
    

    See also https://api.dartlang.org/stable/1.24.3/dart-convert/UTF8-constant.html

    There are also encoder and decoder to be used with streams

    File.openRead().transform(utf8.decoder).
    

    See also https://www.dartlang.org/articles/libraries/converters-and-codecs#converter

    0 讨论(0)
  • 2020-12-17 18:00
    utf8.decode(stringData.runes.toList()),
    

    This could be used to get the UTF-8 in flutter. here the stringData string will contain the necessary data with UTF-8 content.

    0 讨论(0)
提交回复
热议问题