Skip to content

Commit

Permalink
fix: Set button size in onMount if not set (#3413)
Browse files Browse the repository at this point in the history
If the buttons are extended it doesn't automatically propagate the size
from the `button` child component like it does if you pass the button
into the constructor. This PR sets that size in `onMount` if the size is
zero.
  • Loading branch information
spydon authored Dec 16, 2024
1 parent cca1c16 commit 916aa5c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/flame/lib/src/components/input/button_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class ButtonComponent extends PositionComponent with TapCallbacks {
button != null,
'The button has to either be passed in as an argument or set in onLoad',
);
if (size.isZero()) {
size = button!.size;
}
if (!contains(button!)) {
add(button!);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class SpriteButtonComponent extends SpriteGroupComponent<ButtonState>
_button != null,
'The button sprite has to be set either in onLoad or in the constructor',
);
if (size.isZero()) {
size = _button!.originalSize;
}
sprites = {
ButtonState.up: _button!,
ButtonState.down: buttonDown,
Expand Down

0 comments on commit 916aa5c

Please # to comment.