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({required GlobalKey<State<StatefulWidget>> boardKey, required PieceSet pieceSet, required BoardState state, required BoardTheme theme, BoardSize size = const BoardSize(8, 8), HighlightTheme? highlightTheme, int? selection, int? target, bool gameOver = false, bool canMove = false, bool draggable = true, double dragFeedbackSize = 2.0, Offset dragFeedbackOffset = const Offset(0.0, -1.0), dynamic onTap(int, GlobalKey<State<StatefulWidget>>)?, dynamic onDragCancel(int)?, bool validateDrag(PartialMove, int)?, dynamic acceptDrag(PartialMove, int, GlobalKey<State<StatefulWidget>>)?, List<int> highlights = const [], bool allowAnimation = true, Duration? animationDuration, Curve? animationCurve})

Properties

acceptDrag → (dynamic Function(PartialMove, int, GlobalKey<State<StatefulWidget>>)?)
Called when a square accepts a piece dragged onto it.
final
allowAnimation 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
boardKey GlobalKey<State<StatefulWidget>>
A key for the board.
final
canMove bool
If false, premoves will be allowed.
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
gameOver bool
Is the game over?
final
hashCode int
The hash code for this object.
no setterinherited
highlights List<int>
A list of highlighted square indices. Usually this will correspond to squares that the selected piece can move to.
final
highlightTheme HighlightTheme
Widget builders for the various types of square highlights used.
latefinal
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onDragCancel → (dynamic Function(int)?)
Called when a piece drag is cancelled.
final
onTap → (dynamic Function(int, GlobalKey<State<StatefulWidget>>)?)
Called when a square is tapped.
final
pieceSet PieceSet
The set of widgets to use for pieces on the board.
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
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