Temperature=37 , humidity = 60 //data from api
String read =
"humblehacks.xyz/Server.php?patient=Yassen%20Mohamed&request=REQUEST_DATA_DAWNLOAD";
http.Response jread = await http.get(Uri.parse(read));
if (jread.statusCode == 200) {
var body = jread.body;
I am using api to get data , but not by json or xml just string ,
How do I show the data , I can't use Jsondecode because ABI is not Json
i want to display 37 and 60 in app , how can i display it I want full code
Output widgets like text should suffice
Text(37.toString()), // Simple value
Text("Temperature $val"), //String and variable
Text("Temperature ${temp.val}"),//String and map item
Related
How to display Unicode Smiley from json response dynamically in flutter. It's display properly when i declare string as a static but from dynamic response it's not display smiley properly.
Static Declaration: (Working)
child: Text("\ud83d\ude0e\ud83d\ude0eThis is just test notification..\ud83d\ude0e\ud83d\ude0e\ud83d\udcaf\ud83d\ude4c")
Dynamic Response:
"message":"\\ud83d\\ude4c Be Safe at your home \\ud83c\\udfe0",
When i'm parse and pass this response to Text then it's consider Unicode as a String and display as a string instead of Smiley Code is below to display text with smiley:
child: Text(_listData[index].message.toString().replaceAll("\\\\", "\\"))
Already go through this: Question but it's only working when single unicode not working with multiple unicode.
Anyone worked with text along with unicode caracter display dynamically then please let me know.
Another alternate Good Solution I would give to unescape characters is this:
1st ->
String s = "\\ud83d\\ude0e Be Safe at your home \\ud83c\\ude0e";
String q = s.replaceAll("\\\\", "\\");
This would print and wont be able to escape characters:
\ud83d\ud83d Be Safe at your home \ud83c\ud83d
and above would be the output.
So what one can do is either unescape them while parsing or use:
String convertStringToUnicode(String content) {
String regex = "\\u";
int offset = content.indexOf(regex) + regex.length;
while(offset > 1){
int limit = offset + 4;
String str = content.substring(offset, limit);
// print(str);
if(str!=null && str.isNotEmpty){
String uni = String.fromCharCode(int.parse(str,radix:16));
content = content.replaceFirst(regex+str,uni);
// print(content);
}
offset = content.indexOf(regex) + regex.length;
// print(offset);
}
return content;
}
This will replace and convert all the literals into unicode characters and result and output of emoji:
String k = convertStringToUnicode(q);
print(k);
😎 Be Safe at your home 🈎
That is above would be the output.
Note: above answer given would just work as good but this is just when you want to have an unescape function and don't need to use third-party libraries.
You can extend this using switch cases with multiple unescape solutions.
Issue resolved by using below code snippet.
Client client = Client();
final response = await client.get(Uri.parse('YOUR_API_URL'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
final extractedData = json.decode(response.body.replaceAll("\\\\", "\\"));
}
Here we need to replace double backslash to single backslash and then decode JSON respone before set into Text like this we can display multiple unicode like this:
final extractedData = json.decode(response.body.replaceAll("\\",
"\"));
Hope this answer help to other
I'm using a json file to store my data and I need to show some of it on the screen.
For example, when I make a simple text widget and use this string:
Text("a\u2081")
It shows "a" with a subscripted "1".
The problem is that when I load it from a json file it just shows "a\u2081".
This is how I load the data:
var myData = await rootBundle.loadString("data/my_data.json");
var data = await json.decode(myData.toString());
I'm storing the values in objects:
Text(TestReport[i].text) // where TestReport[i].text = "a\u2081"
Is there a way how to show the subscript?
I have the following String:
String readToken = await storage.read(key: 'token');
print(readToken);
The output will be:
flutter: "{\"accessToken\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImFiNWUwYzcwMjYwNWU1MjRmMmZkOTQ2NTAwMDQyZDk1MzBlZWZhYjhkYjA0ZGZjYj<…>
The problem is that the readToken value is a String value so I become in a Map like this.
String decoded = jsonDecode(readToken);
And the output is:
flutter: {"accessToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImFiNWUwYzcwMjYwNWU1MjRmMmZkOTQ2NTAwMDQyZDk1MzBlZWZhYjhkYjA0ZGZjYjIwMWM1ZmE2NjJjOTQxNTA4OTg1MTZhZjBjNmIyYjRkIn0.eyJhdWQiOiIyIiwianRpIjoiYWI1ZTBjNzAyNjA1ZTUyNGYyZmQ5<…>
So it looks like is a Map value but it isn't, because is still a String.
I would like to get just the value for access_token.
I tried
String dec = decoded.replaceAll(RegExp('"'), '');
int pos = dec.indexOf(':');
final token = dec.substring(pos + 1);
You need to decode your string to transform it to an actual Map.
For that you need to use dart:convert package and do the following: json.decode(variable).
I would also suggest to store only the token value in FlutterSecureStorage and not the entire object.
I am getting the data from my JSON file through this code:
var content = await rootBundle.loadString("json/story1.json");
decodedContent = json.decode(content);
And I would like to be able to store an integer inside the story1.json file.
I have an XML object which comes as the response from a web service. I obtain the XML data using
Document xmlDoc = XMLParser.parse( response );
What is the easier and better way to render the xmlDoc in my DialogBox widget?
EDIT
Am having an XML object. I want to render the data inside a panel and show it on the GUI. Hope this helps.
To put in a better way,
Is it possible to directly add XML document to a panel in GWT, or we should parse the same and build the panel ourselves?
Thanks.
you have to parse the web service response
Document messageDom = XMLParser.parse( response );
Then, you can get the node value by
String nodeValue = "";
final NodeList nlist = messageDom.getElementsByTagName( tagName );
if (nlist == null || nlist.getLength() <= 0)
nodeValue = "";
else
nodeValue = nlist.item(0).getFirstChild().getNodeValue();
from here, you can now set panel component value to nodeValue