mirror of https://github.com/flutter/pinball.git
parent
1af0c2e058
commit
a3dc9d09cf
@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
|
||||
class GameHud extends StatelessWidget {
|
||||
const GameHud({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = context.watch<GameBloc>().state;
|
||||
|
||||
return Container(
|
||||
color: Colors.redAccent,
|
||||
width: 200,
|
||||
height: 100,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'${state.score}',
|
||||
style: Theme.of(context).textTheme.headline3,
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
for (var i = 0; i < state.balls; i++)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 6),
|
||||
child: CircleAvatar(
|
||||
radius: 8,
|
||||
backgroundColor: Colors.black,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
export 'game_hud.dart';
|
||||
export 'pinball_game_page.dart';
|
||||
export 'widgets/widgets.dart';
|
||||
|
@ -0,0 +1,32 @@
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
|
||||
import 'package:bloc_test/bloc_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import '../../helpers/helpers.dart';
|
||||
|
||||
void main() {
|
||||
group('GameHud', () {
|
||||
testWidgets(
|
||||
'renders the current score and balls',
|
||||
(tester) async {
|
||||
final state = GameState(score: 10, balls: 2);
|
||||
final gameBloc = MockGameBloc();
|
||||
whenListen(
|
||||
gameBloc,
|
||||
Stream.value(state),
|
||||
initialState: state,
|
||||
);
|
||||
|
||||
await tester.pumpApp(
|
||||
GameHud(),
|
||||
gameBloc: gameBloc,
|
||||
);
|
||||
|
||||
expect(find.text('10'), findsOneWidget);
|
||||
expect(find.byType(CircleAvatar), findsNWidgets(2));
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
Loading…
Reference in new issue