Closed edwinaceron closed 2 years ago
@edwinaceron What do you mean by dynamically creating a TextField?
I am using
@edwinaceron You can pass previously created controllers to the TextFields you create and receive field values through them.
Yes controller is needed for each TextField but how could you pass controller on each TextField? I don't think passing one controller like the following code will work:
StyledText(
style: TextStyle(
height: 1.0,
fontSize: 25.0,
color: Colors.grey,
),
text: widget.question.question,
tags: {
'BLANK': StyledTextWidgetTag(
TextField(
controller: _controller;
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 1.0,),
),
),
style: TextStyle(
height: 1.0,
fontSize: 25.0,
color: Colors.grey,
),
controller:
),
size: Size.fromWidth(300),
constraints: BoxConstraints.tight(Size(200, 50)),
),
},
)
@edwinaceron You can pass the controller as usual, but for two different fields, you need to use two different tags in your text.
I think passing that way is not the best solution because number of blanks is not fixed. It might have 2, 3, 4, or 5 blanks. I am working on a quiz or a test app that would have Fill In the Blanks questions.
@edwinaceron You can pass a key in the tag attribute, and when creating a TextField, create a controller and save a link to it in the Map with a key from the attribute.
I will add the ability to receive tag attributes to StyledTextWidgetTag in the coming days.
I'm looking forward for it, Sir. As of now I can't find any solution to my problem. Thanks.
@edwinaceron I have released an updated version, you can use StyledTextWidgetBuilderTag to create TextFields and save controllers to Map using keys from attributes.
Thanks @andyduke!
Any reference that could use to get dynamically created TextFields by tag?