fix: apply code review

pull/206/head
arturplaczek 3 years ago
parent 57337138c8
commit 111295d89e

@ -1,13 +1,13 @@
// ignore_for_file: public_member_api_docs
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/gen/gen.dart';
/// {@template game_hud}
/// Overlay of a [PinballGame] that displays the current [GameState.score],
/// [GameState.balls] and animation when the player get the bonus.
/// Overlay of a [PinballGame].
///
/// Displays the current [GameState.score], [GameState.balls] and animates when
/// the player gets a [GameBonus].
/// {@endtemplate}
class GameHud extends StatefulWidget {
/// {@macro game_hud}
@ -33,7 +33,7 @@ class _GameHudState extends State<GameHud> {
height: _width / _ratio,
width: _width,
child: BlocListener<GameBloc, GameState>(
listenWhen: _listenWhen,
listenWhen: _listenWhenBonusChanges,
listener: (_, __) => setState(() => showAnimation = true),
child: AnimatedSwitcher(
duration: kThemeAnimationDuration,
@ -52,7 +52,7 @@ class _GameHudState extends State<GameHud> {
);
}
bool _listenWhen(GameState previous, GameState current) {
bool _listenWhenBonusChanges(GameState previous, GameState current) {
final previousCount = previous.bonusHistory.length;
final currentCount = current.bonusHistory.length;
return previousCount != currentCount;
@ -74,10 +74,10 @@ class _ScoreViewDecoration extends StatelessWidget {
child: DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
Assets.images.score.miniScoreBackground.path,
),
fit: BoxFit.cover,
),
),
child: child,
@ -86,6 +86,7 @@ class _ScoreViewDecoration extends StatelessWidget {
}
}
// TODO(arturplaczek): implement new Sprite animation when will be merged.
class _AnimationView extends StatelessWidget {
const _AnimationView({
Key? key,

@ -17,7 +17,7 @@ class ScoreBalls extends StatelessWidget {
return Row(
children: [
Text(
l10n.ballCt,
l10n.rounds,
style: AppTextStyle.subtitle1.copyWith(
color: AppColors.orange,
),
@ -47,12 +47,14 @@ class ScoreBall extends StatelessWidget {
@override
Widget build(BuildContext context) {
final color = isActive ? AppColors.orange : AppColors.orange.withAlpha(128);
const size = 8.0;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Container(
color: color,
height: 8,
width: 8,
height: size,
width: size,
),
);
}

@ -2,10 +2,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/theme/theme.dart';
import 'package:pinball_components/pinball_components.dart';
class ScoreView extends StatelessWidget {
const ScoreView({Key? key}) : super(key: key);
@ -72,11 +72,9 @@ class _ScoreText extends StatelessWidget {
@override
Widget build(BuildContext context) {
final score = context.select((GameBloc bloc) => bloc.state.score);
final numberFormatter = NumberFormat.decimalPattern('en_US');
final formattedScore = numberFormatter.format(score).replaceAll(',', '.');
return Text(
formattedScore,
score.formatScore(),
style: AppTextStyle.headline1.copyWith(
color: AppColors.white,
),

@ -76,8 +76,8 @@
"@enterInitials": {
"description": "Text displayed on the ending dialog when game finishes to ask the user for his initials"
},
"ballCt": "Ball Ct:",
"@ballCt": {
"rounds": "Rounds:",
"@rounds": {
"description": "Text displayed on the scoreboard widget"
}
}

@ -73,7 +73,6 @@ void main() {
final state = initialState.copyWith(
bonusHistory: [GameBonus.dashNest],
);
stateController.add(state);
await tester.pumpApp(
@ -92,7 +91,6 @@ void main() {
final state = initialState.copyWith(
bonusHistory: [gameBonus],
);
whenListen(
gameBloc,
Stream.value(state),
@ -100,7 +98,6 @@ void main() {
);
await _pumpAppWithWidget(tester);
await tester.pump();
expect(find.byType(BonusAnimation), findsOneWidget);
@ -115,7 +112,6 @@ void main() {
final state = initialState.copyWith(
bonusHistory: [GameBonus.dashNest],
);
whenListen(
gameBloc,
Stream.value(state),
@ -123,9 +119,9 @@ void main() {
);
await _pumpAppWithWidget(tester);
await tester.pump();
// TODO(arturplaczek): remove magic number once this is merged:
// https://github.com/flame-engine/flame/pull/1564
await Future<void>.delayed(const Duration(seconds: 4));
await expectLater(find.byType(ScoreView), findsOneWidget);

@ -3,9 +3,9 @@ import 'dart:async';
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/intl.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball_components/pinball_components.dart';
import '../../../helpers/helpers.dart';
@ -30,11 +30,6 @@ void main() {
);
});
String _formatScore(int score) {
final numberFormatter = NumberFormat.decimalPattern('en_US');
return numberFormatter.format(score).replaceAll(',', '.');
}
group('ScoreView', () {
testWidgets('renders score', (tester) async {
await tester.pumpApp(
@ -43,7 +38,7 @@ void main() {
);
await tester.pump();
expect(find.text(_formatScore(score)), findsOneWidget);
expect(find.text(score.formatScore()), findsOneWidget);
});
testWidgets('renders game over', (tester) async {
@ -70,7 +65,7 @@ void main() {
gameBloc: gameBloc,
);
expect(find.text(_formatScore(score)), findsOneWidget);
expect(find.text(score.formatScore()), findsOneWidget);
final newState = initialState.copyWith(
score: 987654321,
@ -80,7 +75,7 @@ void main() {
await tester.pump();
expect(find.text(_formatScore(newState.score)), findsOneWidget);
expect(find.text(newState.score.formatScore()), findsOneWidget);
});
});
}

Loading…
Cancel
Save