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). So, How can I convert string to utf8 in Dart?
Example:
@httpGet
Future<Response> 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);
}
The return is not in TR-tr language format.
Return text looks like:
**1:_:2:_:175997:_:NÝYAZÝ TOROS**
Correct must be:
**1:_:2:_:175997:_:NİYAZİ TOROS**
UPDATE:
xResult = new String.fromCharCodes(data).trim();
print(xResult);
responseBody = xResult.transform(utf8.decoder);
print(responseBody);
I can print the xResult
but cannot print the responseBody
after trying convert to UTF8
transform
? You are not using a stream. – Schwartzprint(utf8.decode(data));
– Schwartzdata
. – Schwartz