lichess-org / flutter-chessground

Chessboard package for flutter
https://pub.dev/packages/chessground
GNU General Public License v3.0
46 stars 29 forks source link
chessboard dart flutter lichess

Tests pub package package publisher Discord

Chessground is a chessboard package developed for lichess.org. It doesn't handle chess logic so you can use it with different chess variants.

Features

Getting started

This package exports a Chessboard widget which can be interactable or not.

It is configurable with a ChessboardSettings object which defines the board behavior and appearance.

To interact with the board in order to play a game, you must provide a GameData object to the Chessboard widget. This object is immutable and contains the game state (which side is to move, the current valid moves, etc.), along with the callback functions to handle user interactions.

All chess logic must be handled outside of this package. Any change in the state of the game needs to be transferred to the board by creating a new GameData object.

Usage

This will display a non-interactable board from the starting position, using the default theme:

import 'package:flutter/material.dart';
import 'package:chessground/chessground.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR';

  @override
  Widget build(BuildContext context) {
    final double screenWidth = MediaQuery.of(context).size.width;

    return Scaffold(
      appBar: AppBar(
        title: const Text('Chessground demo'),
      ),
      body: Center(
        child: Chessboard.fixed(
          size: screenWidth,
          orientation: Side.white,
          fen: fen,
        ),
      ),
    );
  }
}

See the example app for: