-
-
Notifications
You must be signed in to change notification settings - Fork 871
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
feat: Adding ComponentNotifier API #1889
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very useful to me!
I like this! Does this mean that I can do something like the following? class Entity extends PositionComponent with Notifiable {
Color _color = Color(0xffffffff);
Color get color => _color;
set color(Color value) {
_color = value;
notifyChanges();
}
} And then the UI can be like the following? Widget build(context) {
// I am probably butchering provider's API here, but hopefully you get the idea.
final color = context.select<ComponentsNotifier<Entity>, Color>((e) => e.color);
return Container(
color: color,
child: Text(entity.name),
);
} |
Yes! Exactly |
e508fa5
to
60cabf8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm! It looks like a lot of comments, but most actually just regard one thing; that the name Notifiable
should be changed (#1889 (comment)). :)
packages/flame/lib/src/widgets/components_notifier_builder.dart
Outdated
Show resolved
Hide resolved
Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
Description
This adds a proposal for a new API for flame, the
ComponentNotifier
.This API offers the user change notifiers classes that are tied to
FlameGame
and its components so the user can be notified when a component is added, removed or updated.This will enable users to:
One important note here is that this proposal does not mean to replace integrations like
flame_bloc
, but rather provider an simple and out of the box solution, without any need of additional packages, since change notifiers are provided by flutter itself.Opening this as draft for now to get feedback on the implementation, will write tests and docs once we have the final implementation.
Demo of the example:
Screen.Recording.2022-09-05.at.18.21.57.mov
Checklist
fix:
,feat:
,docs:
etc).docs
and added dartdoc comments with///
.examples
.Breaking Change
Related Issues