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
59 lines
1.9 KiB
Dart
59 lines
1.9 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mchess/chess/chess_square.dart';
|
|
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
|
import 'package:mchess/chess_bloc/tap_bloc.dart';
|
|
import 'package:mchess/utils/chess_utils.dart';
|
|
|
|
class ChessSquareInnerDraggable extends StatelessWidget {
|
|
const ChessSquareInnerDraggable({
|
|
super.key,
|
|
required this.coordinate,
|
|
required this.containedPiece,
|
|
});
|
|
|
|
final ChessCoordinate coordinate;
|
|
final ChessPiece? containedPiece;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
double windowWidth = MediaQuery.of(context).size.width;
|
|
double windowHeight = MediaQuery.of(context).size.height;
|
|
double draggableFdbSize;
|
|
|
|
var canMove = (ChessBloc.turnColor == ChessBloc.myColor) &&
|
|
(containedPiece?.color == ChessBloc.turnColor);
|
|
var maxDrags = kDebugMode ? 1 : (canMove ? 1 : 0);
|
|
|
|
if (windowWidth < windowHeight) {
|
|
draggableFdbSize = 0.15 * windowWidth;
|
|
} else {
|
|
draggableFdbSize = 0.15 * windowHeight;
|
|
}
|
|
|
|
return SizedBox(
|
|
width: ChessSquare.pieceWidth,
|
|
height: ChessSquare.pieceWidth,
|
|
child: Draggable<PieceDragged>(
|
|
/* We create the move with the startSquare == endSquare. The receiving widget will give the correct value to end square. */
|
|
data: PieceDragged(coordinate, coordinate, containedPiece),
|
|
maxSimultaneousDrags: maxDrags,
|
|
feedback: FractionalTranslation(
|
|
translation: const Offset(-0.5, -0.75),
|
|
child: SizedBox(
|
|
height: draggableFdbSize,
|
|
width: draggableFdbSize,
|
|
child: containedPiece),
|
|
),
|
|
childWhenDragging: Container(),
|
|
dragAnchorStrategy: pointerDragAnchorStrategy,
|
|
child: containedPiece ?? Container(),
|
|
onDragCompleted: () {},
|
|
onDragStarted: () {
|
|
TapBloc().add(CancelTapEvent());
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|