Board class

The visual representation of the board. Can be used by itself to simply display a board, or in conjunction with BoardController or some other wrapper to manage its state and handle interactions.

Inheritance

Constructors

Board({Key? key, required BoardState state, PlayState playState = PlayState.observing, required PieceSet pieceSet, BoardTheme theme = BoardTheme.blueGrey, BoardSize size = BoardSize.standard, MarkerTheme? markerTheme, int? selection, int? target, List<PieceSelectorData> pieceSelectors = const [], bool draggable = true, double dragFeedbackSize = 2.0, Offset dragFeedbackOffset = const Offset(0.0, -1.0), PlayerSet dragPermissions = PlayerSet.both, DragTargetFeedback? dragTargetFeedback, void onTap(int)?, void onPieceSelected(PieceSelectorData data, int i)?, void onDragCancel(int)?, bool validateDrag(PartialMove, int)?, void acceptDrag(PartialMove, int)?, List<int> markers = const [], bool animatePieces = true, Duration animationDuration = Squares.defaultAnimationDuration, Curve animationCurve = Squares.defaultAnimationCurve, List<Widget> underlays = const [], List<Widget> overlays = const [], bool externalDrag = false, LabelConfig labelConfig = LabelConfig.standard, BackgroundConfig backgroundConfig = BackgroundConfig.standard, Widget? background, double piecePadding = 0.0})

Properties

acceptDrag → (void Function(PartialMove, int)?)
Called when a square accepts a piece dragged onto it.
final
animatePieces bool
If true and there is a last move, it will be animated.
final
animationCurve Curve
Animation curve for piece movements. Defaults to Curves.easeInQuad.
final
animationDuration Duration
How long move animations take to play.
final
background Widget?
A widget to be placed behind everything on the board. Useful for games with backgrounds like Xiangqi. If you use this then you need to either set boardConfig or set the colour of the basic squares in theme to transparent.
final
backgroundConfig BackgroundConfig
Configuration for the background. Determines which squares to draw, and allows an opacity for squares to be defined.
final
dragFeedbackOffset Offset
A vector to offset the position of dragged pieces by, relative to the size of the piece. No offset is recommended for web, and Offset(0,-1) for mobile, in which case the bottom of the piece will be anchored to the finger.
final
dragFeedbackSize double
The size of pieces being dragged will be multiplied by this. 1.5 is a good value for mobile, but 1.0 is preferable for web.
final
draggable bool
Whether pieces should be draggable or not.
final
dragPermissions PlayerSet
Which players' pieces we can drag.
final
dragTargetFeedback DragTargetFeedback?
Builds feedback for squares being hovered over by a dragged piece.
final
externalDrag bool
Set this to true if an external drag is in progress. When true, this disables the gesture detectors on the piece layer, allowing external drags to land.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
labelConfig LabelConfig
Configuration for the rank and file labels on the board. Set this to LabelConfig.disabled to hide them entirely.
final
markers List<int>
A list of highlighted square indices. Usually this will correspond to squares that the selected piece can move to.
final
markerTheme MarkerTheme
Widget builders for the various types of square markers used.
latefinal
onDragCancel → (void Function(int)?)
Called when a piece drag is cancelled.
final
onPieceSelected → (void Function(PieceSelectorData data, int i)?)
Called when a piece selector receives user input.
final
onTap → (void Function(int)?)
Called when a square is tapped.
final
overlays List<Widget>
A list of widgets that will be inserted on top of the piece layer, but below any visible piece selectors. Ensure these don't absorb any gestures to preserve board behaviour.
final
piecePadding double
Padding to add on every side of a piece, relative to the size of the square it is on. For example, 0.05 will add 5% padding to each side.
final
pieceSelectors List<PieceSelectorData>
Configuration of visible piece selectors (for promo and gating).
final
pieceSet PieceSet
The set of widgets to use for pieces on the board.
final
playState PlayState
The state of the game, from the perspective of the player.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selection int?
The currently selected square index.
final
size BoardSize
Dimensions of the board.
final
state BoardState
The state of the board - which pieces are on which squares, etc.
final
target int?
The currently selected target square index (for premoves).
final
theme BoardTheme
Colour scheme for the board.
final
underlays List<Widget>
A list of widgets that will be inserted between the board background and the piece layer. Ensure these don't absorb any gestures to preserve board behaviour.
final
validateDrag → (bool Function(PartialMove, int)?)
Called when a piece moves over a new square. This includes external pieces, such as those that came from hands.
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited