New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Being able to copyWith a ReactiveTextField OR expose the fields of ReactiveTextField #126
Comments
Hi @naamapps, Thanks for using Reactive Forms and for the issue. I'm not sure I understand your issue. I know that you have created a custom Widget that listens for changes of control using a ReactiveValueListenableBuilder. But I don't understand the problem with ReactiveTextField. Could you please argue more about the issue or put some code examples? Thanks |
Here is the code: Click to expand!
As you can see, I manually type every field you wrote in the ReactiveTextField contractor and pass it to ReactiveTextField. Pass the ReactiveTextField instead of all the fields above,
Hope it's more understandable now. |
Hey @joanpablo any updates on this? |
Hi @naamapps, Sorry not yet. Next weekend I will let you know. Thanks |
ReactiveTextField is a widget. You don't copy widgets. |
Hi @naamapps, Yeap @kuhnroyal is right, we will need to find a way to solve your issue, but is not adding a method copyWith to the ReactiveTextField. We need to rethink your issue and find a better solution. |
@joanpablo |
Well in Flutter you just wrap it in another widget. Use smart defaults that fit your needs. Maybe a couple different factories and you are done. |
I'm agree with @kuhnroyal |
@joanpablo @kuhnroyal |
Tbh, I didn't fully read you problem until now. Alternatively you can create a custom builder
This is mainly caused by changes in Flutter and there is not much anyone can do about it. |
Hi @naamapps, The main difficulty for implementing the copyWIth in the ReactiveTextField is that I don't hold all the properties as fields in the class. All properties that are passed by the constructor, like textDirection, decoration, etc, are directly passed to the constructor of the inner TextField, and I never hold them (never define them as properties of the ReactiveTextField class). This is the main reason I can't implement this feature. But if you create your own custom widget and want to define all those properties as properties of the class, then you can do it in your own widget. This is the only solution I can give you right now. You have shown me in previous examples that you actually do this, you define each property of the ReactiveTextField as a property of the AutoDirectionTextField widget, so you can actually implement a copyWith method in your own widget. |
Hi @joanpablo, I'm not sure I understand why you pass the properties in the constructor directly and you don't save them. The other solution is to make a builder function that accepts text direction and returns reactive text field. If you have any other suggestion I would be glad to hear. |
Because in this case For your use-case, to change the text-direction, why not just wrap everything in a new return ReactiveValueListenableBuilder(
formControlName: reactiveTextField.formControlName,
formControl: reactiveTextField.formControl,
builder: (context, control, child) {
bool isRTLResult = Directionality.of(context) == TextDirection.rtl;
if (control.value != null && control.value.toString().isNotBlank) {
isRTLResult = isRTL(control.value.toString());
}
return Directionality(
textDirection: isRTLResult ? TextDirection.rtl : TextDirection.ltr,
child: reactiveTextField,
);
}
); |
@kuhnroyal, |
I see, well then you need to construct it in the builder. Don't see any other way. |
I have settled with a builder:
Thank you guys for your help! |
Hi,
I implemented a widget called
AutoDirectionTextField
which usesReactiveValueListenableBuilder
to update the text direction when the text of the field updates according to the language the user typed.The problem is that it is not manageable because with each update there are some breaking changes and new parameters to the
ReactiveTextField
.There are two options to tackle this:
The solution would be to expose the fields or add a copyWith method to allow us to copy an existing ReactiveTextField and override them if needed.
Please help,
Thanks
The text was updated successfully, but these errors were encountered: