title: How can I convert string to utf8 in Dart?
body: <p>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 exact string (in tr). S<strong>o, How can I convert string to utf8 in Dart?</strong></p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>@httpGet
  Future&lt;Response&gt; getLogin() async {
    Socket.connect('192.168.1.22’, 1024).then((socket) async {
      socket.listen((data) {
        // Expected return is: 1:_:2:_:175997:_:NİYAZİ TOROS
        print(new String.fromCharCodes(data).trim());
        xResult = new String.fromCharCodes(data).trim();
        print("xResult: $xResult");
      }, onDone: () {
        print("Done");
        socket.destroy();
      });
  
      socket.write('Q101:_:49785:_:x\r\n');
    });
  
    return new Response.ok(xResult);
  }
  </code></pre>
  
  <p>The return is not in TR-tr language format. </p>
  
  <p>Return text looks like:
  <strong>1:<em>:2:</em>:175997:_:NÝYAZÝ TOROS</strong></p>
  
  <p>Correct must be:
  <strong>1:<em>:2:</em>:175997:_:NİYAZİ TOROS</strong></p>
  
  <p>UPDATE:</p>
  
  <ol>
  <li><code>xResult = new String.fromCharCodes(data).trim();</code></li>
  <li><code>print(xResult);</code></li>
  <li><code>responseBody = xResult.transform(utf8.decoder);</code></li>
  <li><code>print(responseBody);</code></li>
  </ol>
  
  <p>I can print the <code>xResult</code> but cannot print the <code>responseBody</code> after trying convert to UTF8</p>