Reputation: 701
I want to split the text data in Text widget after getting from api call. Here is the code
Row(
children:<Widget>[
Text('result'),
Text(item[pos].asr), //getting the data from api call which is "22:00"
RaisedButton(
onpressed(){
print()// here i want to show the split text data which is "22" then "00" under "22"
}
),
]
)
Upvotes: 0
Views: 4157
Reputation: 6186
You can split using split
function as:
List<String> splitted = item[pos].asr.split(":"); // list containing 22 and 00.
to print 22, use -> splitted[0]
and for 00, use -> splitted[1]
Upvotes: 1
Reputation: 1678
Let try it:
Row(
children:<Widget>[
Text('result'),
Text(item[pos].asr),
RaisedButton(
onPressed: () {
List<String> arr = item[pos].asr.split(':');
int hour = int.parse(arr[0]);
int minutes = int.parse(arr[1]);
print(hour.toString() + " " + minutes.toString());
},
),
]
)
Upvotes: 2
Reputation: 1951
you can store splitted value in list
var string = "22:00";
List splitedText = string.split(":");
print(splitedText[0]);
print(splitedText[1]);
Upvotes: 0