diff --git a/lib/game/view/pinball_game_page.dart b/lib/game/view/pinball_game_page.dart index be6615f1..c0d5d1d8 100644 --- a/lib/game/view/pinball_game_page.dart +++ b/lib/game/view/pinball_game_page.dart @@ -114,14 +114,6 @@ class PinballGameLoadedView extends StatelessWidget { @override Widget build(BuildContext context) { - final isPlaying = context.select( - (StartGameBloc bloc) => bloc.state.status == StartGameStatus.play, - ); - final gameWidgetWidth = MediaQuery.of(context).size.height * 9 / 16; - final screenWidth = MediaQuery.of(context).size.width; - final leftMargin = (screenWidth / 2) - (gameWidgetWidth / 1.8); - final clampedMargin = leftMargin > 0 ? leftMargin : 0.0; - return StartGameListener( child: Stack( children: [ @@ -141,16 +133,36 @@ class PinballGameLoadedView extends StatelessWidget { }, ), ), - Positioned( - top: 0, - left: clampedMargin, - child: Visibility( - visible: isPlaying, - child: const GameHud(), - ), - ), + const _PositionedGameHud(), ], ), ); } } + +class _PositionedGameHud extends StatelessWidget { + const _PositionedGameHud({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final isPlaying = context.select( + (StartGameBloc bloc) => bloc.state.status == StartGameStatus.play, + ); + final isGameOver = context.select( + (GameBloc bloc) => bloc.state.status.isGameOver, + ); + final gameWidgetWidth = MediaQuery.of(context).size.height * 9 / 16; + final screenWidth = MediaQuery.of(context).size.width; + final leftMargin = (screenWidth / 2) - (gameWidgetWidth / 1.8); + final clampedMargin = leftMargin > 0 ? leftMargin : 0.0; + + return Positioned( + top: 0, + left: clampedMargin, + child: Visibility( + visible: isPlaying && !isGameOver, + child: const GameHud(), + ), + ); + } +} diff --git a/test/game/view/pinball_game_page_test.dart b/test/game/view/pinball_game_page_test.dart index f78f6278..5aef07dd 100644 --- a/test/game/view/pinball_game_page_test.dart +++ b/test/game/view/pinball_game_page_test.dart @@ -260,5 +260,36 @@ void main() { findsOneWidget, ); }); + + testWidgets('hide a hud on game over', (tester) async { + final startGameState = StartGameState.initial().copyWith( + status: StartGameStatus.play, + ); + final gameState = GameState.initial().copyWith( + status: GameStatus.gameOver, + ); + + whenListen( + startGameBloc, + Stream.value(startGameState), + initialState: startGameState, + ); + whenListen( + gameBloc, + Stream.value(gameState), + initialState: gameState, + ); + + await tester.pumpApp( + PinballGameView(game: game), + gameBloc: gameBloc, + startGameBloc: startGameBloc, + ); + + expect( + find.byType(GameHud), + findsNothing, + ); + }); }); }