stockfish 0.1.0 copy "stockfish: ^0.1.0" to clipboard
stockfish: ^0.1.0 copied to clipboard

PlatformAndroidiOS
outdated

The Stockfish Chess Engine for Flutter.

example/lib/main.dart

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

import 'src/output_widget.dart';

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

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _AppState();
}

class _AppState extends State<MyApp> {
  late Stockfish stockfish;

  @override
  void initState() {
    super.initState();
    stockfish = Stockfish();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Stockfish example app'),
        ),
        body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: AnimatedBuilder(
                animation: stockfish.state,
                builder: (_, __) => Text(
                  'stockfish.state=${stockfish.state.value}',
                  key: ValueKey('stockfish.state'),
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: AnimatedBuilder(
                animation: stockfish.state,
                builder: (_, __) => ElevatedButton(
                  onPressed: stockfish.state.value == StockfishState.disposed
                      ? () {
                          final newInstance = Stockfish();
                          setState(() => stockfish = newInstance);
                        }
                      : null,
                  child: Text('Reset Stockfish instance'),
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextField(
                autocorrect: false,
                decoration: InputDecoration(
                  labelText: 'Custom UCI command',
                  hintText: 'go infinite',
                ),
                onSubmitted: (value) => stockfish.stdin = value,
                textInputAction: TextInputAction.send,
              ),
            ),
            Wrap(
              children: [
                'd',
                'isready',
                'go infinite',
                'go movetime 3000',
                'stop',
                'quit',
              ]
                  .map(
                    (command) => Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: ElevatedButton(
                        onPressed: () => stockfish.stdin = command,
                        child: Text(command),
                      ),
                    ),
                  )
                  .toList(growable: false),
            ),
            Expanded(
              child: OutputWidget(stockfish.stdout),
            ),
          ],
        ),
      ),
    );
  }
}
27
likes
140
points
312
downloads

Publisher

verified publisherarjanaswal.com

Weekly Downloads

The Stockfish Chess Engine for Flutter.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

ffi, flutter

More

Packages that depend on stockfish