mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-13 19:30:14 +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();
|
final onLoadFuture = onLoad();
|
||||||
if (onLoadFuture == null) {
|
if (onLoadFuture == null) {
|
||||||
_state = LifecycleState.loaded;
|
_state = LifecycleState.loaded;
|
||||||
|
_loadCompleter?.complete();
|
||||||
} else {
|
} else {
|
||||||
return onLoadFuture.then((_) {
|
return onLoadFuture.then((_) {
|
||||||
_state = LifecycleState.loaded;
|
_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
|
// Obsolete scenario, when we used to have a separate "prepare" stage
|
||||||
flameGame.test('parent prepares the component', (game) async {
|
flameGame.test('parent prepares the component', (game) async {
|
||||||
final parent = _MyComponent('parent');
|
final parent = _MyComponent('parent');
|
||||||
|
|||||||
Reference in New Issue
Block a user