-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Extending PreferenceBuilder to multiple values #6
Comments
Great idea! I'm working on it. I'll likely have support for listening to 3 preferences. If you need more than that, you should maybe rethink your code. That said, I'll make it easy to extend to more than 3 preferences. |
@TheBestMoshe & @degloff this is the current plan. Let's say we have these three preferences: PreferenceBuilder3<String, int, bool>(
preferences.getString('name'),
preferences.getInt('age'),
preferences.getBool('isAwesome'),
builder: (BuildContext context, String name, int age, bool isAwesome) {
// Do something with "name", "age", and "isAwesome" typed values.
},
) It works a bit like The order of the arguments in the There's also a I'm not making typedef PreferenceWidgetBuilder4<A, B, C, D> = Widget Function(
BuildContext context,
A a,
B b,
C c,
D d,
);
class PreferenceBuilder4<A, B, C, D> extends PreferenceBuilderBase<dynamic> {
PreferenceBuilder4(
this.a,
this.b,
this.c,
this.d, {
Key key,
@required this.builder,
}) : super(preferences: [a, b, c, d], key: key);
final Preference<A> a;
final Preference<B> b;
final Preference<C> c;
final Preference<D> d;
final PreferenceWidgetBuilder4<A, B, C, D> builder;
@override
Widget build(BuildContext context, List<dynamic> values) {
return builder(
context,
values[0] as A,
values[1] as B,
values[2] as C,
values[3] as D,
);
}
} I should have this on the master branch this week, then I'll do some testing and make a new release. Let me know what you think! |
I like the PreferenceBuilder a lot. It would be even better if there would be a MultiPreferenceBuilder that allows to listen on multiple changing values, probably with Rx.combineLatest. It is a bit tedious to implement, as we would need to have it for 2, 3, 4, etc. Would it be possible to add such a feature?
The text was updated successfully, but these errors were encountered: