mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-13 11:20:19 +08:00
fix: Component.loaded future sometimes failed to complete (#1593)
This commit is contained in:
@@ -501,6 +501,7 @@ class Component {
|
||||
final onLoadFuture = onLoad();
|
||||
if (onLoadFuture == null) {
|
||||
_state = LifecycleState.loaded;
|
||||
_loadCompleter?.complete();
|
||||
} else {
|
||||
return onLoadFuture.then((_) {
|
||||
_state = LifecycleState.loaded;
|
||||
|
||||
@@ -117,6 +117,17 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWithFlameGame(
|
||||
'.loaded completes even if accessed before the component added to game',
|
||||
(game) async {
|
||||
final component = Component();
|
||||
final loadedFuture = component.loaded;
|
||||
game.add(component);
|
||||
await game.ready();
|
||||
expectLater(loadedFuture, completes);
|
||||
},
|
||||
);
|
||||
|
||||
// Obsolete scenario, when we used to have a separate "prepare" stage
|
||||
flameGame.test('parent prepares the component', (game) async {
|
||||
final parent = _MyComponent('parent');
|
||||
|
||||
Reference in New Issue
Block a user