chessboard_js 0.0.2+1 copy "chessboard_js: ^0.0.2+1" to clipboard
chessboard_js: ^0.0.2+1 copied to clipboard

outdated

A chessboard widget to use with chessjs. Use chessjs for the logic of the game, and this package to display the game.

example/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:chessboard_js/chessboard_js.dart';

void main() {
  runApp(ProviderScope(child: 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(),
    );
  }
}

final moveProvider = StateProvider<String>((ref) => '');

class ChessGame extends ConsumerWidget {
  @override
  Widget build(BuildContext context, ScopedReader watch) {
    final ChessboardController controller =
        ChessboardController(onMove: (move) {
      print('move: $move');
    });

    return Scaffold(
      backgroundColor: Colors.black,
      body: SizedBox.expand(
        child: Theme(
          data: ThemeData.dark(),
          child: Row(
            children: [
              ChessBoard(
                initialSize: 400,
                minSize: 300,
                controller: controller,
              ),
              Column(
                children: [
                  Text('Test Moves', style: TextStyle(color: Colors.white)),
                  Container(
                    width: 200,
                    child: TextField(
                      onChanged: (value) {
                        context.read(moveProvider).state = value;
                      },
                    ),
                  ),
                  TextButton(
                      onPressed: () {
                        final move = context.read(moveProvider).state;
                        bool moveMade = controller.makeSanMove(move);
                        if (!moveMade) {
                          showDialog(
                              context: context,
                              builder: (context) =>
                                  AlertDialog(title: Text('Illegal Move')));
                        }
//                        print(controller.getSanHistory());
                      },
                      child: Text('Submit')),
                  TextButton(
                      onPressed: () {
                        if (controller.movesEnabled)
                          controller.disableUserMoves();
                        else
                          controller.enableUserMove();
                      },
                      child: Text('Enable/Disable Moves'))
                ],
              )
            ],
          ),
        ),
      ),
    );
  }
}
3
likes
0
pub points
0%
popularity

Publisher

verified publishercarlosalejano.app

A chessboard widget to use with chessjs. Use chessjs for the logic of the game, and this package to display the game.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

chessjs, equatable, flutter, flutter_hooks, hooks_riverpod, tuple

More

Packages that depend on chessboard_js