mirror of https://github.com/flutter/pinball.git
parent
dba7761e01
commit
ca989eac8d
@ -1,25 +0,0 @@
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
|
||||
class PinballGameView extends StatelessWidget {
|
||||
const PinballGameView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<GameBloc, GameState>(
|
||||
listener: (context, state) {
|
||||
if (state.isGameOver) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
return const GameOverDialog();
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
child: GameWidget<PinballGame>(game: PinballGame()),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,3 +1,2 @@
|
||||
export 'pinball_game_page.dart';
|
||||
export 'pinball_game_view.dart';
|
||||
export 'widgets/widgets.dart';
|
||||
|
@ -1,46 +0,0 @@
|
||||
import 'package:bloc_test/bloc_test.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
|
||||
import '../../helpers/helpers.dart';
|
||||
|
||||
void main() {
|
||||
group('PinballGameView', () {
|
||||
testWidgets('renders game', (tester) async {
|
||||
final gameBloc = MockGameBloc();
|
||||
whenListen(
|
||||
gameBloc,
|
||||
Stream.value(const GameState.initial()),
|
||||
initialState: const GameState.initial(),
|
||||
);
|
||||
|
||||
await tester.pumpApp(const PinballGameView(), gameBloc: gameBloc);
|
||||
expect(
|
||||
find.byWidgetPredicate((w) => w is GameWidget<PinballGame>),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'renders a game over dialog when the user has lost',
|
||||
(tester) async {
|
||||
final gameBloc = MockGameBloc();
|
||||
const state = GameState(score: 0, balls: 0);
|
||||
whenListen(
|
||||
gameBloc,
|
||||
Stream.value(state),
|
||||
initialState: state,
|
||||
);
|
||||
|
||||
await tester.pumpApp(const PinballGameView(), gameBloc: gameBloc);
|
||||
await tester.pump();
|
||||
|
||||
expect(
|
||||
find.text('Game Over'),
|
||||
findsOneWidget,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
Loading…
Reference in new issue