From 0ab37c55642031ccf8dea16b84091516262365e2 Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 13 Nov 2022 03:50:29 +0100 Subject: [PATCH] Change pre-checking to be method-driven instead of event-driven, so we can get the return value. --- lib/chess_bloc/chess_bloc.dart | 5 ++--- lib/chessapp/chess_square.dart | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/chess_bloc/chess_bloc.dart b/lib/chess_bloc/chess_bloc.dart index fbca3fa..2ba4711 100644 --- a/lib/chess_bloc/chess_bloc.dart +++ b/lib/chess_bloc/chess_bloc.dart @@ -8,7 +8,6 @@ class ChessBloc extends Bloc { ChessBloc._internal() : super(ChessBoardState.init()) { on(moveHandler); - on(preCheckHandler); } factory ChessBloc.getInstance() { @@ -36,11 +35,11 @@ class ChessBloc extends Bloc { )); } - void preCheckHandler( + bool preCheckHandler( PreCheckMove event, - Emitter emit, ) { print('Pretending to check a move before you drop a piece'); + return true; } } diff --git a/lib/chessapp/chess_square.dart b/lib/chessapp/chess_square.dart index cab703e..9865d37 100644 --- a/lib/chessapp/chess_square.dart +++ b/lib/chessapp/chess_square.dart @@ -54,8 +54,10 @@ class ChessSquare extends StatelessWidget { ); }, onWillAccept: (move) { - ChessBloc().add(PreCheckMove(move: move!)); - return true; + final legalMove = + ChessBloc().preCheckHandler(PreCheckMove(move: move!)); + print('onWillAccept returns $legalMove'); + return legalMove; }, onAccept: (move) { move.endSquare = coordinate;