Open fzyzcjy opened 2 years ago
This is quite helpful, because in the MobX world, it would be great if everything is observable, and TextField is very frequently used :)
@pavanpodila If the prototype looks good I will PR for it.
I think these kind of things should be kept in a separate package: mobx_extensions. We should do that and then over time based on maturity we can bring them into core
Thanks for the reply. I will create that package later when having time.
So, maybe the documentation of mobx can mention that extensions package? Since these are quite useful things.
This would be very useful in a package. Along with other Observable form fields.
Was this ever made? I can't find mobx_extensions
No it was not, but I have been using it for a long time. Below is the latest code copy-pasted from my internal library, which is fairly simple.
P.S. In addition to SyncTextField, there is SyncIntTextField which handles integer input.
@fzyzcjy this seems super interesting, looks like this will allow me to send the mobx observable to the TextField right? How do you use the GetSet class? It looks like you use this class to wrap mobx observables and the send the GetSet to the TextField right?
Would you be so kind to show me how to use this using a Mobx Store?
Thanks
looks like this will allow me to send the mobx observable to the TextField right?
Yes, automatically synchronize textfield with observable.
GetSet
class GetSet<T> {
T Function() getter;
void Function(T value) setter;
GetSet({required this.getter, required this.setter});
GetSet.gs(this.getter, this.setter);
}
Usage:
class YourStore { @observable String a; }
SyncTextField(
gs: GetSet(getter: () => yourStore.a, setter: (value) => yourStore.a = value),
)
@fzyzcjy thank you Yo! I'm using it already in my app. works great!
Not sure exactly how it works but I'll figure it out.
You are welcome!
Currently, as is seen in the example, TextField's text is not observable.
My naive attempt is as follows. Not sure whether this helps!