flutter_stateless_chessboard 1.1.2 copy "flutter_stateless_chessboard: ^1.1.2" to clipboard
flutter_stateless_chessboard: ^1.1.2 copied to clipboard

A Chessboard Widget for Flutter. This package provides just the chessboard. The game logic can be implemented using chess library.

example/lib/main.dart

import 'dart:math';

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

import 'utils.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Random Chess App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String _fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';

  @override
  Widget build(BuildContext context) {
    final viewport = MediaQuery.of(context).size;
    final size = min(viewport.height, viewport.width);

    return Scaffold(
      appBar: AppBar(
        title: Text("Random Chess"),
      ),
      body: Center(
        child: Chessboard(
          fen: _fen,
          size: size,
          orientation: BoardColor.WHITE,
          onMove: (move) {
            final nextFen = makeMove(_fen, {
              'from': move.from,
              'to': move.to,
              'promotion': 'q',
            });

            if (nextFen != null) {
              setState(() {
                _fen = nextFen;
              });

              Future.delayed(Duration(milliseconds: 300)).then((_) {
                final nextMove = getRandomMove(_fen);

                if (nextMove != null) {
                  setState(() {
                    _fen = makeMove(_fen, nextMove) ?? _fen;
                  });
                }
              });
            }
          },
        ),
      ),
    );
  }
}
25
likes
70
points
43
downloads

Publisher

unverified uploader

Weekly Downloads

A Chessboard Widget for Flutter. This package provides just the chessboard. The game logic can be implemented using chess library.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

chess, chess_vectors_flutter, flutter, fpdart, provider

More

Packages that depend on flutter_stateless_chessboard