Marco
200393ac76
With the previous change of starting a tap on a drag, we removed the GestureDetector from all squares with any pieces. This included the opponent's pieces. Tapping and taking an opponent's piece was not possible anymore. This was a bug, since we still want to detect a tap and take an opponent's piece.
55 lines
1.8 KiB
Dart
55 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mchess/chess/chess_square_inner_draggable.dart';
|
|
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
|
import 'package:mchess/chess_bloc/chess_events.dart';
|
|
import 'package:mchess/chess_bloc/promotion_bloc.dart';
|
|
import 'package:mchess/chess_bloc/tap_bloc.dart';
|
|
import 'package:mchess/utils/chess_utils.dart';
|
|
|
|
class ChessSquareOuterDragTarget extends StatelessWidget {
|
|
final ChessCoordinate coordinate;
|
|
final ChessPiece containedPiece;
|
|
|
|
const ChessSquareOuterDragTarget(
|
|
{super.key, required this.coordinate, required this.containedPiece});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DragTarget<PieceDragged>(
|
|
onWillAcceptWithDetails: (details) {
|
|
if (details.data.fromSquare == coordinate) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
onAcceptWithDetails: (details) {
|
|
// Replace the dummy value with the actual target of the move.
|
|
details.data.toSquare = coordinate;
|
|
|
|
TapBloc().add(CancelTapEvent());
|
|
|
|
if (isPromotionMove(
|
|
details.data.movedPiece!.pieceClass,
|
|
ChessBloc.getMyColor(),
|
|
details.data.toSquare,
|
|
)) {
|
|
var move = ChessMove(
|
|
from: details.data.fromSquare, to: details.data.toSquare);
|
|
PromotionBloc().add(PawnMovedToPromotionField(
|
|
move: move, colorMoved: ChessBloc.myColor));
|
|
} else if (coordinate != details.data.fromSquare) {
|
|
ChessBloc().add(OwnPieceMoved(
|
|
startSquare: details.data.fromSquare,
|
|
endSquare: details.data.toSquare));
|
|
}
|
|
},
|
|
builder: (context, candidateData, rejectedData) {
|
|
return ChessSquareInnerDraggable(
|
|
coordinate: coordinate,
|
|
containedPiece: containedPiece,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|