Change pre-checking to be method-driven instead of event-driven, so we can get the return value.

This commit is contained in:
Marco 2022-11-13 03:50:29 +01:00
parent 8ebc010e63
commit 0ab37c5564
2 changed files with 6 additions and 5 deletions

View File

@ -8,7 +8,6 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
ChessBloc._internal() : super(ChessBoardState.init()) { ChessBloc._internal() : super(ChessBoardState.init()) {
on<PieceMoved>(moveHandler); on<PieceMoved>(moveHandler);
on<PreCheckMove>(preCheckHandler);
} }
factory ChessBloc.getInstance() { factory ChessBloc.getInstance() {
@ -36,11 +35,11 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
)); ));
} }
void preCheckHandler( bool preCheckHandler(
PreCheckMove event, PreCheckMove event,
Emitter<ChessBoardState> emit,
) { ) {
print('Pretending to check a move before you drop a piece'); print('Pretending to check a move before you drop a piece');
return true;
} }
} }

View File

@ -54,8 +54,10 @@ class ChessSquare extends StatelessWidget {
); );
}, },
onWillAccept: (move) { onWillAccept: (move) {
ChessBloc().add(PreCheckMove(move: move!)); final legalMove =
return true; ChessBloc().preCheckHandler(PreCheckMove(move: move!));
print('onWillAccept returns $legalMove');
return legalMove;
}, },
onAccept: (move) { onAccept: (move) {
move.endSquare = coordinate; move.endSquare = coordinate;