flutter_chessboard_js 0.0.2+7 flutter_chessboard_js: ^0.0.2+7 copied to clipboard
A chessboard widget to use with chessjs. Use chessjs for the logic of the game, and this package to display the game.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:chessjs/chessjs.dart' as chessjs;
import 'package:flutter_chessboard_js/flutter_chessboard_js.dart' as chessboard;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ChessGame(),
);
}
}
class ChessGame extends StatefulWidget {
@override
_ChessGameState createState() => _ChessGameState();
}
class _ChessGameState extends State<ChessGame> {
String? move;
@override
Widget build(BuildContext context) {
final chessboard.ChessboardController chessboardController =
chessboard.ChessboardController(
chessjsGame: chessjs.Chess(),
onMove: (move) {
print('move: $move');
});
return Scaffold(
backgroundColor: Colors.black,
body: SizedBox.expand(
child: Theme(
data: ThemeData.dark(),
child: Row(
children: [
chessboard.ChessBoard(
initialSize: 400,
minSize: 300,
controller: chessboardController,
),
],
),
),
),
);
}
}