Skip to content
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

fix: Buttons in ButtonComponents should not be final #2410

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/flame/lib/src/components/input/button_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:meta/meta.dart';
/// Note: You have to set the [button] in [onLoad] if you are not passing it in
/// through the constructor.
class ButtonComponent extends PositionComponent with Tappable {
late final PositionComponent? button;
late final PositionComponent? buttonDown;
PositionComponent? button;
PositionComponent? buttonDown;

/// Callback for what should happen when the button is pressed.
void Function()? onPressed;
Expand Down
18 changes: 18 additions & 0 deletions packages/flame/test/components/hud_button_component_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,23 @@ void main() {
expect(releasedTimes, 1);
expect(cancelledTimes, 1);
});

testWithGame<GameWithTappables>(
'can set button and buttonDown in onLoad', GameWithTappables.new,
(game) async {
expect(
() => game.ensureAdd(_CustomHudButtonComponent()),
returnsNormally,
);
});
});
}

class _CustomHudButtonComponent extends HudButtonComponent {
@override
Future<void> onLoad() async {
super.onLoad();
button = RectangleComponent(size: Vector2.all(10));
buttonDown = CircleComponent(radius: 10);
}
}