-
-
Notifications
You must be signed in to change notification settings - Fork 892
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
refactor!: The method onLoad()
now returns FutureOr<void>
#2228
Conversation
Is this really a breaking change? I don't think this will break any existing code right? |
It's barely breaking. Like, the following example would no longer work, because @override
Future<void>? onLoad() {
width = 200;
height = 70;
return super.onLoad();
} But then, these kind of examples are rare (there is no point in calling |
Good idea! |
i can't find onLoad function in flame 1.6.0 version |
Please put questions in either on Discord, in issues or on StackOverflow.
|
Thanks. I found it, because android studio doesn't show recommended for onload function i thought it was removed from flame. |
Description
Before this PR, the return type of
onLoad()
wasFuture<void>?
, after this PR the return type isFutureOr<void>
-- both for classesComponent
andGame
.Reasons:
FutureOr
is more idiomatic in Dart, this class was specifically created in order to be used in situations like ours.onLoad()
is one of the first methods the user encounters in Flame).onLoad
doesn't need to be async.With new approach, the
onLoad()
method can be overridden as eitheror
Of course, it can also be overridden as
but this is rare, only for components that are designed to be further subclassed, or for mixins.
The documentation was updated to show the new recommended usage.
Checklist
fix:
,feat:
,docs:
etc).docs
and added dartdoc comments with///
.examples
ordocs
.Breaking Change?
Migration instructions
Most of the existing code is expected to work as-is. In particular, the following patterns will continue to work:
@override Future<void> onLoad() async { ... }
;@override Future<void> onLoad() async { await super.onLoad(); ... }
;@override Future<void> onLoad() { ...; return super.onLoad(); }
;@override Future<void>? onLoad() { ...; return null; }
;However, the following pattern will no longer work:
@override Future<void>? onLoad() { ...; return super.onLoad(); }
Instead, it will now produce a compile error, which can be fixed by changing the signature to one of
@override void onLoad() { ...; }
(in most cases the call tosuper.onLoad()
is not needed);@override void onLoad() { ...; super.onLoad(); }
;@override FutureOr<void> onLoad() { ...; return super.onLoad(); }
;Related Issues