refactor: included initial factory constructor

pull/3/head
alestiago 4 years ago
parent 24d85630e3
commit db46b6d521

@ -6,7 +6,7 @@ part 'game_event.dart';
part 'game_state.dart'; part 'game_state.dart';
class GameBloc extends Bloc<GameEvent, GameState> { class GameBloc extends Bloc<GameEvent, GameState> {
GameBloc() : super(const GameState(score: 0, balls: 3)) { GameBloc() : super(GameState.initial()) {
on<BallLost>(_onBallLost); on<BallLost>(_onBallLost);
on<Scored>(_onScored); on<Scored>(_onScored);
} }

@ -11,6 +11,11 @@ class GameState extends Equatable {
}) : assert(score >= 0, "Score can't be negative"), }) : assert(score >= 0, "Score can't be negative"),
assert(balls >= 0, "Number of balls can't be negative"); assert(balls >= 0, "Number of balls can't be negative");
factory GameState.initial() => const GameState(
score: 0,
balls: 3,
);
/// The current score of the game. /// The current score of the game.
final int score; final int score;

Loading…
Cancel
Save