stagexl_interactive_chessboard 1.1.0

StageXL Interactive Chessboard #

An interactive chessboard written for StageXL which allows players to move pieces.

alt text

Example #

Chessboard board = Chessboard();

It is fully compatible with chess.dart #

Chess.Chess chess = Chess.Chess()

Any square can have its background color set #

board.setSquareBackgroundColor("e1", 0xaa27b243);

Capture when squares are clicked #

board.onSquareClicked.listen((ChessEvent event) {

Show and hide the labels around the board #

board.showLabels = true;

Change which way round the board is #

board.blackAtTop = false;

1.1.0 - 25/02/2018. #

  • decoupled square from chessboard so it can be used independantly.

1.0.0 - 20/02/2018. #

  • Initial version


import 'dart:async';
import 'dart:html' as html;
import 'package:stagexl/stagexl.dart';
import 'package:stagexl_interactive_chessboard/stagexl_interactive_chessboard.dart';
import 'dart:math';
import 'package:chess/chess.dart' as Chess;

Stage stage;

Future<Null> main() async {
  StageOptions options = StageOptions()
    ..backgroundColor = Color.White
    ..stageScaleMode =StageScaleMode.NO_SCALE
    ..stageAlign =StageAlign.TOP_LEFT
    ..renderEngine = RenderEngine.WebGL;

  var canvas = html.querySelector('#stage');
  stage = Stage(canvas, width: 1280, height: 800, options: options);

  var renderLoop = RenderLoop();

  Chessboard board = Chessboard();
  board.blackAtTop = false;
  num size = min(stage.stageWidth, stage.stageHeight);
  size -= 20;
  board.setSize(size, size);

  board.x = (stage.stageWidth - board.width) / 2;
  board.y = (stage.stageHeight - board.height) / 2;
  Chess.Chess chess = Chess.Chess()

  board.onSquareClicked.listen((ChessEvent event) {
    board.setSquareBackgroundColor(event.squareName, 0xaa27b243);

    List<Chess.Move> moves = chess.generate_moves({"square": event.squareName});
    for (Chess.Move move in moves) {
      board.setSquareBackgroundColor(, 0xaaffffb2);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  stagexl_interactive_chessboard: ^1.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:stagexl_interactive_chessboard/stagexl_interactive_chessboard.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Aug 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19


Detected platforms: web

Primary library: package:stagexl_interactive_chessboard/stagexl_interactive_chessboard.dart with components: html.

Health suggestions

Fix lib/src/Chessboard.dart. (-1 points)

Analysis of lib/src/Chessboard.dart reported 2 hints:

line 45 col 3: Avoid return types on setters.

line 54 col 3: Avoid return types on setters.

Fix lib/src/BottomLabels.dart. (-0.50 points)

Analysis of lib/src/BottomLabels.dart reported 1 hint:

line 8 col 3: Avoid return types on setters.

Fix lib/src/LeftLabels.dart. (-0.50 points)

Analysis of lib/src/LeftLabels.dart reported 1 hint:

line 8 col 3: Avoid return types on setters.

Fix additional 3 files with analysis or formatting issues. (-0.50 points)

Additional issues in the following files:

  • lib/src/PieceFactory.dart (1 hint)
  • lib/src/ChessEvent.dart (Run dartfmt to format lib/src/ChessEvent.dart.)
  • lib/stagexl_interactive_chessboard.dart (Run dartfmt to format lib/stagexl_interactive_chessboard.dart.)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
chess ^0.6.5 0.6.5
stagexl ^1.1.0 1.4.0+3
stagexl_chess_pieces ^1.0.1 1.0.1
Transitive dependencies
charcode 1.1.2
collection 1.14.12
convert 2.1.1
meta 1.1.7
petitparser 2.4.0
typed_data 1.1.6
xml 3.5.0