0

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"
}
),
]
)

3 Answers 3

2

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());
          },
        ),
      ]
  )
Sign up to request clarification or add additional context in comments.

Comments

1

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]

1 Comment

Already Text(item[pos].asr) has the data which displays 22:00 when i run on mobile screen, you have mention the 'hardcoded' declared string.
0

you can store splitted value in list

var string = "22:00"; 
List splitedText = string.split(":");
print(splitedText[0]);
print(splitedText[1]);

1 Comment

Already Text(item[pos].asr) has the data which displays 22:00 when i run on mobile screen, you have mention the 'hardcoded' declared string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.