Merge pull request 'Start a tap with drag' (#7) from drag-starts-tap into master

Reviewed-on: #7
This commit is contained in:
marco 2024-02-01 11:19:57 +01:00
commit ecca9f07c3
6 changed files with 83 additions and 40 deletions

1
devtools_options.yaml Normal file
View File

@ -0,0 +1 @@
extensions:

View File

@ -59,17 +59,23 @@ class ChessSquare extends StatefulWidget {
class _ChessSquareState extends State<ChessSquare> {
@override
Widget build(BuildContext context) {
return GestureDetector(
child: Container(
color: widget.color,
child: ChessSquareOuterDragTarget(
coordinate: widget.coordinate,
containedPiece: widget.containedPiece ?? const ChessPiece.none()),
),
onTap: () {
TapBloc().add(SquareTappedEvent(
tapped: widget.coordinate, pieceOnSquare: widget.containedPiece));
},
var dragTarget = Container(
color: widget.color,
child: ChessSquareOuterDragTarget(
coordinate: widget.coordinate,
containedPiece: widget.containedPiece ?? const ChessPiece.none()),
);
if (widget.containedPiece == null) {
return GestureDetector(
child: dragTarget,
onTap: () {
TapBloc().add(SquareTappedEvent(
tapped: widget.coordinate, pieceOnSquare: widget.containedPiece));
},
);
} else {
return dragTarget;
}
}
}

View File

@ -50,7 +50,8 @@ class ChessSquareInnerDraggable extends StatelessWidget {
child: containedPiece ?? Container(),
onDragCompleted: () {},
onDragStarted: () {
TapBloc().add(CancelTapEvent());
TapBloc().add(SquareTappedEvent(
tapped: coordinate, pieceOnSquare: containedPiece));
},
),
);

View File

@ -3,6 +3,7 @@ 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 {
@ -15,29 +16,31 @@ class ChessSquareOuterDragTarget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DragTarget<PieceDragged>(
onWillAccept: (move) {
if (move?.fromSquare == coordinate) {
onWillAcceptWithDetails: (details) {
if (details.data.fromSquare == coordinate) {
return false;
}
return true;
},
onAccept: (pieceDragged) {
onAcceptWithDetails: (details) {
// Replace the dummy value with the actual target of the move.
pieceDragged.toSquare = coordinate;
details.data.toSquare = coordinate;
TapBloc().add(CancelTapEvent());
if (isPromotionMove(
pieceDragged.movedPiece!.pieceClass,
details.data.movedPiece!.pieceClass,
ChessBloc.myColor!,
pieceDragged.toSquare,
details.data.toSquare,
)) {
var move = ChessMove(
from: pieceDragged.fromSquare, to: pieceDragged.toSquare);
from: details.data.fromSquare, to: details.data.toSquare);
PromotionBloc().add(PawnMovedToPromotionField(
move: move, colorMoved: ChessBloc.myColor!));
} else if (coordinate != pieceDragged.fromSquare) {
} else if (coordinate != details.data.fromSquare) {
ChessBloc().add(OwnPieceMoved(
startSquare: pieceDragged.fromSquare,
endSquare: pieceDragged.toSquare));
startSquare: details.data.fromSquare,
endSquare: details.data.toSquare));
}
},
builder: (context, candidateData, rejectedData) {

View File

@ -85,10 +85,10 @@ packages:
dependency: transitive
description:
name: ffi
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.2"
file:
dependency: transitive
description:
@ -148,10 +148,10 @@ packages:
dependency: "direct main"
description:
name: go_router
sha256: "3b40e751eaaa855179b416974d59d29669e750d2e50fcdb2b37f1cb0ca8c803a"
sha256: "07ee2436909f749d606f53521dc1725dd738dc5196e5ff815bc254253c594075"
url: "https://pub.dev"
source: hosted
version: "13.0.1"
version: "13.1.0"
http:
dependency: "direct main"
description:
@ -168,6 +168,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints:
dependency: transitive
description:
@ -188,26 +212,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.0"
nested:
dependency: transitive
description:
@ -220,10 +244,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
path_parsing:
dependency: transitive
description:
@ -469,22 +493,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "0.4.2"
web_socket_channel:
dependency: "direct main"
description:
name: web_socket_channel
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
sha256: "939ab60734a4f8fa95feacb55804fa278de28bdeef38e616dc08e44a84adea23"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
version: "2.4.3"
win32:
dependency: transitive
description:
@ -510,5 +542,5 @@ packages:
source: hosted
version: "6.5.0"
sdks:
dart: ">=3.2.0 <4.0.0"
dart: ">=3.3.0-279.1.beta <4.0.0"
flutter: ">=3.16.0"

View File

@ -40,7 +40,7 @@ dependencies:
cupertino_icons: ^1.0.2
flutter_bloc: ^8.1.3
quiver: ^3.1.0
web_socket_channel: ^2.4.0
web_socket_channel: ^2.4.3
go_router: ^13.0.0
http: ^1.0.0
uuid: ^4.0.0