SOUGAT RIYADH
SOUGAT RIYADH

Reputation: 701

How to split the text data after getting from api in Flutter

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

Answers (3)

OMi Shah
OMi Shah

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

duongdt3
duongdt3

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

Jay Gadariya
Jay Gadariya

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

Related Questions