Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated dependency and Bloc Code #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions lib/game/blocs/game_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class GameBloc extends Bloc<GameEvent, GameState> {
this.snakeInitialLength = 4,
this.updatePeriod = 150,
}) : assert(random != null),
assert(snakeInitialLength >= 4) {
assert(snakeInitialLength >= 4),
super(GameState(
status: Status.loading,
score: 0,
velocity: Vec2d(0, -1),
)) {
add(LoadAssetsEvent());
}

Expand All @@ -38,15 +43,6 @@ class GameBloc extends Bloc<GameEvent, GameState> {
/// The game update period in milliseconds.
final int updatePeriod;

@override
GameState get initialState {
return GameState(
status: Status.loading,
score: 0,
velocity: Vec2d(0, -1),
);
}

Future<void> _preloadAssets() async {
await flameManager?.setup();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/game/screens/game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class GameScreen extends StatelessWidget {
title: const Text("Snaake"),
actions: <Widget>[
BlocBuilder<GameBloc, GameState>(
condition: (before, after) => before.status != after.status,
buildWhen: (before, after) => before.status != after.status,
builder: (context, state) {
switch (state.status) {
case Status.pause:
Expand Down Expand Up @@ -129,7 +129,7 @@ class GameScreen extends StatelessWidget {
_gameRenderer.updateSnake(state.snake);
},
child: BlocBuilder<GameBloc, GameState>(
condition: (before, current) => before.status != current.status,
buildWhen: (before, current) => before.status != current.status,
builder: (context, state) {
final bloc = BlocProvider.of<GameBloc>(context);
return state.status == Status.loading
Expand Down
Loading