fix: apply code review

pull/184/head
arturplaczek 3 years ago
parent cfa6e5abc4
commit 61938057b4

@ -14,28 +14,28 @@ class StartGameBloc extends Bloc<StartGameEvent, StartGameState> {
required PinballGame game,
}) : _game = game,
super(const StartGameState.initial()) {
on<StartGame>(_onStartGame);
on<HowToPlay>(_onHowToPlay);
on<Play>(_onPlay);
on<PlayTapped>(_onStartGame);
on<CharacterSelected>(_onCharacterSelected);
on<HowToPlayFinished>(_onHowToPlayFinished);
}
final PinballGame _game;
void _onStartGame(
StartGame event,
PlayTapped event,
Emitter<StartGameState> emit,
) {
_game.gameFlowController.start();
emit(
state.copyWith(
status: StartGameStatus.startGame,
status: StartGameStatus.selectCharacter,
),
);
}
void _onHowToPlay(
HowToPlay event,
void _onCharacterSelected(
CharacterSelected event,
Emitter<StartGameState> emit,
) {
emit(
@ -45,8 +45,8 @@ class StartGameBloc extends Bloc<StartGameEvent, StartGameState> {
);
}
void _onPlay(
Play event,
void _onHowToPlayFinished(
HowToPlayFinished event,
Emitter<StartGameState> emit,
) {
emit(

@ -8,34 +8,34 @@ abstract class StartGameEvent extends Equatable {
const StartGameEvent();
}
/// {@template select_character}
/// Select character event.
/// {@template play_tapped}
/// Play tapped event.
/// {@endtemplate}
class StartGame extends StartGameEvent {
/// {@macro select_character}
const StartGame();
class PlayTapped extends StartGameEvent {
/// {@macro play_tapped}
const PlayTapped();
@override
List<Object> get props => [];
}
/// {@template how_to_play}
/// How to play event.
/// {@template character_selected}
/// Character selected event.
/// {@endtemplate}
class HowToPlay extends StartGameEvent {
/// {@macro how_to_play}
const HowToPlay();
class CharacterSelected extends StartGameEvent {
/// {@macro character_selected}
const CharacterSelected();
@override
List<Object> get props => [];
}
/// {@template play}
/// Play event.
/// {@template how_to_play_finished}
/// How to play finished event.
/// {@endtemplate}
class Play extends StartGameEvent {
/// {@macro play}
const Play();
class HowToPlayFinished extends StartGameEvent {
/// {@macro how_to_play_finished}
const HowToPlayFinished();
@override
List<Object> get props => [];

@ -2,11 +2,11 @@ part of 'start_game_bloc.dart';
/// Defines status of start game flow.
enum StartGameStatus {
/// Starting status.
/// Initial status.
initial,
/// Selection characters status.
startGame,
selectCharacter,
/// How to play status.
howToPlay,

@ -0,0 +1 @@
export 'bloc/start_game_bloc.dart';

@ -21,24 +21,24 @@ void main() {
group('StartGameBloc', () {
blocTest<StartGameBloc, StartGameState>(
'on StartGame changes status to StartGame',
'on PlayTapped changes status to selectCharacter',
build: () => StartGameBloc(
game: pinballGame,
),
act: (bloc) => bloc.add(const StartGame()),
act: (bloc) => bloc.add(const PlayTapped()),
expect: () => [
const StartGameState(
status: StartGameStatus.startGame,
status: StartGameStatus.selectCharacter,
)
],
);
blocTest<StartGameBloc, StartGameState>(
'on HowToPlay changes status to howToPlay',
'on CharacterSelected changes status to howToPlay',
build: () => StartGameBloc(
game: pinballGame,
),
act: (bloc) => bloc.add(const HowToPlay()),
act: (bloc) => bloc.add(const CharacterSelected()),
expect: () => [
const StartGameState(
status: StartGameStatus.howToPlay,
@ -47,11 +47,11 @@ void main() {
);
blocTest<StartGameBloc, StartGameState>(
'on Play changes status to play',
'on HowToPlayFinished changes status to play',
build: () => StartGameBloc(
game: pinballGame,
),
act: (bloc) => bloc.add(const Play()),
act: (bloc) => bloc.add(const HowToPlayFinished()),
expect: () => [
const StartGameState(
status: StartGameStatus.play,

@ -5,24 +5,24 @@ import 'package:pinball/start_game/bloc/start_game_bloc.dart';
void main() {
group('StartGameEvent', () {
test('StartGame supports value equality', () {
test('PlayTapped supports value equality', () {
expect(
StartGame(),
equals(StartGame()),
PlayTapped(),
equals(PlayTapped()),
);
});
test('HowToPlay supports value equality', () {
test('CharacterSelected supports value equality', () {
expect(
HowToPlay(),
equals(HowToPlay()),
CharacterSelected(),
equals(CharacterSelected()),
);
});
test('Play supports value equality', () {
test('HowToPlayFinished supports value equality', () {
expect(
Play(),
equals(Play()),
HowToPlayFinished(),
equals(HowToPlayFinished()),
);
});
});

@ -6,7 +6,7 @@ import 'package:pinball/start_game/bloc/start_game_bloc.dart';
void main() {
group('StartGameState', () {
final testState = StartGameState(
status: StartGameStatus.startGame,
status: StartGameStatus.selectCharacter,
);
test('initial state has correct values', () {
@ -19,7 +19,7 @@ void main() {
test('supports value equality', () {
final secondState = StartGameState(
status: StartGameStatus.startGame,
status: StartGameStatus.selectCharacter,
);
expect(testState, secondState);
@ -35,7 +35,7 @@ void main() {
expect(
testState.props,
equals([
StartGameStatus.startGame,
StartGameStatus.selectCharacter,
]),
);
});

Loading…
Cancel
Save