andyduke / styled_text_package

Text widget with formatted text using tags. Makes it easier to use formatted text in multilingual applications.
https://pub.dev/packages/styled_text
BSD 3-Clause "New" or "Revised" License
74 stars 48 forks source link

Can't get reference of dynamically created TextFields by tag #36

Closed edwinaceron closed 2 years ago

edwinaceron commented 2 years ago

Any reference that could use to get dynamically created TextFields by tag?

andyduke commented 2 years ago

@edwinaceron What do you mean by dynamically creating a TextField?

edwinaceron commented 2 years ago

I am using tag to produce or generate a TextField like the following sample text: The quick fox jumps over the lazy . It will create 2 TextFields that user should enter brown and dog respectively. I am looking for a reference to access those two TextFields to get the value entered by the user.

andyduke commented 2 years ago

@edwinaceron You can pass previously created controllers to the TextFields you create and receive field values through them.

edwinaceron commented 2 years ago

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

andyduke commented 2 years ago

@edwinaceron You can pass the controller as usual, but for two different fields, you need to use two different tags in your text.

edwinaceron commented 2 years ago

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.

andyduke commented 2 years ago

@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.

edwinaceron commented 2 years ago

I'm looking forward for it, Sir. As of now I can't find any solution to my problem. Thanks.

andyduke commented 2 years ago

@edwinaceron I have released an updated version, you can use StyledTextWidgetBuilderTag to create TextFields and save controllers to Map using keys from attributes.

edwinaceron commented 2 years ago

Thanks @andyduke!