Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add onTappedSquare to Chessboard widget, add squareHighlights field #66

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tom-anders
Copy link
Contributor

We'll need this if we want to switch the coordinate trainer in the app
from ChessboardEditor to Chessboard in order to fix lichess-org/mobile#1017

We'll need this if we want to switch the coordinate trainer in the app
from `ChessboardEditor` to `Chessboard` in order to fix lichess-org/mobile#1017
@tom-anders tom-anders changed the title feat: add onTappedSquare to Chessboard widget, add sqaureHighlights field feat: add onTappedSquare to Chessboard widget, add squareHighlights field Dec 26, 2024
lib/src/widgets/board.dart Outdated Show resolved Hide resolved
@@ -549,6 +570,8 @@ class _BoardState extends State<Chessboard> {
final square = widget.offsetSquare(details.localPosition);
if (square == null) return;

widget.onTappedSquare?.call(square);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this onTapped is misleading since the callback is executed on pointer down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah I wasn't sure whether to put this into pointer down or up - Now that I think about it again, if we call it onTapped it should probably be in pointer up instead? And we should only invoke the callback if the pointer up happened on the same square as the previous pointer down event

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should we keep it in _onPointerDown and change the callback's name instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on what we want to do. Pointer down will feel more responsive compared to tap down. But, iirc we want to use it for the coordinates learn tool, right? I think on tap is more relevant here, what do you think?

In that case the best, and easiest way to implement it is to directly use the onTap handler of the GestureDetector.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's for the coordinate trainer - added the GestureDetector 👍

test/widgets/board_test.dart Outdated Show resolved Hide resolved
child: Stack(
alignment: Alignment.topLeft,
children: highlightedBackground,
final board = GestureDetector(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I forgot that we weren't using a GestureDetector when I suggested to use it... 😄

What you wrote looks fine, but I wonder if there is any drawback to have the Listener as a child of a GestureDetector?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that was the reason why I also initially hesitated to add it :D but I think with HitTestBehavior.translucent it shouldn't cause any problems, all the events will be passed along to the child, regardless of whether we handled them or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and the tests still pass, so looks like at least there aren't any regression (can't promise no new bugs of course)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sliding your finger in coordinate trainer continues to select squares
2 participants