0

I am a beginner in flutter, how do i get or retrieve data from text widget. I have done some practice for example

Text("18:00"),
var data=Text("18:00");
print(data);

At the end instead of getting "18:00" i am getting "Text("17:05")" at the output.

3 Answers 3

2

define this

var data = "18:00";

Text("18:00"),

print(data);
Sign up to request clarification or add additional context in comments.

2 Comments

var data = "18:00"; Text(data), print(data); if i do something like this. But this does not help his problem. Question is why print showing 17:55
that's fine but when i tried this var data = Text("18:00"); and then when i print("${data}"); my output is Text("18:00").
1

To retrieve data fom a Text widget,

var data=Text("18:00");
print(data.data);

This will give you the output "18:00" as per your requirement.

Comments

0

what do you want to do? if you want to get an input from user you should use text field or forms by setting controller to it and get data from controller.

 final myController = TextEditingController();
    TextField(controller: myController),
     var data=mycontroller.getText();

or if you want just get the text of text widget just set that text to a variable then pass it to widget.

String data="18:00"
 Text(data);

Comments

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.