stockfish 0.0.1 stockfish: ^0.0.1 copied to clipboard
The Stockfish Chess Engine for Flutter.
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> {
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();
if (newInstance == null) return;
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),
),
],
),
),
);
}
}