Marco
212a54612c
This adds an option to dragging-and-dropping which is slightly hard on smaller screens. Fix promotions when tapping and fix handling of subsequently tapping two pieces of your color Cancel tap if a drag is started (tapped square will not stay red in case a drag is started) Change url strategy back to the hashtag thing Change version Fix bug that would not allow a piece move if you tried to take an opponents piece. Fix the coloring of the last move after an invalid move was played. Upgrading deps
52 lines
1.7 KiB
Dart
52 lines
1.7 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/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>(
|
|
onWillAccept: (move) {
|
|
if (move?.fromSquare == coordinate) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
onAccept: (pieceDragged) {
|
|
// Replace the dummy value with the actual target of the move.
|
|
pieceDragged.toSquare = coordinate;
|
|
|
|
if (isPromotionMove(
|
|
pieceDragged.movedPiece!.pieceClass,
|
|
ChessBloc.myColor!,
|
|
pieceDragged.toSquare,
|
|
)) {
|
|
var move = ChessMove(
|
|
from: pieceDragged.fromSquare, to: pieceDragged.toSquare);
|
|
PromotionBloc().add(PawnMovedToPromotionField(
|
|
move: move, colorMoved: ChessBloc.myColor!));
|
|
} else if (coordinate != pieceDragged.fromSquare) {
|
|
ChessBloc().add(OwnPieceMoved(
|
|
startSquare: pieceDragged.fromSquare,
|
|
endSquare: pieceDragged.toSquare));
|
|
}
|
|
},
|
|
builder: (context, candidateData, rejectedData) {
|
|
return ChessSquareInnerDraggable(
|
|
coordinate: coordinate,
|
|
containedPiece: containedPiece,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|