Change pre-checking to be method-driven instead of event-driven, so we can get the return value.
This commit is contained in:
parent
8ebc010e63
commit
0ab37c5564
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user