goban 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

Goban #

Goban

Customizable Go board widget for Flutter.

Usage #

Initialize a GobanController like so:

gobanController = GobanController(boardSize: BoardSize.Thirteen);

Then subscribe to the move stream:

gobanController.gobanStream.stream.listen((Position position) {
    // A move at 'position' was played
    // Decide what to do here
});

Whenever an intersection is clicked, the above method will fire.

Goban does not have any game logic; this is by design. Goban make no assumptions on what you want to do, so that it can be used for all purposes. Maybe you want to use it for Tsumego purposes, or maybe you want to use it for online multiplayer. Both of these required different logic, therefore Goban delegates all game logic responsibilities to the client.

For example, a simple local board would be:

player = Player.Black;

gobanController.gobanStream.stream.listen((Position position) {
    // A move at 'position; has been made.
    var clickedPlayer = gobanController.getPlayerFromPosition(pos); // Get the intersection at 'position'
    if (clickedPlayer == Player.Empty) { // If the intersection is empty;
        var move = Move(player, pos); // Create move

        gobanController.addMove(move); // Make the move on the goban.

        setState(() {
            player = player == Player.Black ? Player.White : Player.Black; // Other players' turn
        });
    }
});

Please see here for a more concrete example.

Customization Options #

The board and the stones are fully customizable:

gobanController = GobanController(
    boardSize: BoardSize.Nine,
    gobanTheme: GobanTheme(
        stoneThemes: StoneThemes(
            blackStoneTheme: BlackStoneTheme(
                stoneColor: Colors.black45, borderColor: Colors.black),
            whiteStoneTheme: WhiteStoneTheme(
                borderColor: Colors.white, stoneColor: Colors.tealAccent)),
        boardTheme: BoardTheme(
            boardColor: Colors.yellow,
            lineColor: Colors.red,
            lineWidth: 3)));

Aside from the default theme, there are also two preset themes available:

Book Theme #

Book Theme

gobanController = GobanController(
    boardSize: boardSize, gobanTheme: GobanTheme.bookTheme());

Jade Theme #

Jade Theme

gobanController = GobanController(
    boardSize: boardSize, gobanTheme: GobanTheme.jadeTheme());

Todo #

  • Stone shadow when while pressing down
  • Ability to show just one corner (like SmartGo on iOS)
  • Coordinates
  • SGF support

[0.1.2] - 2019-07-12

  • Formatting fixes for pub.

[0.1.1] - 2019-07-12

  • Small fixes for pub.

[0.1.0] - 2019-07-12

  • Initial release!

example/main.dart

import 'package:flutter/material.dart';
import 'package:goban/data_classes/move.dart';
import 'package:goban/enums/player.dart';
import 'package:goban/gobanController.dart';
import 'package:goban/themes/gobanTheme.dart';
import 'package:goban/data_classes/position.dart';
import 'package:goban/enums/boardSize.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Goban Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Player player = Player.Black;
  String gobanTheme = 'default';
  BoardSize boardSize = BoardSize.Thirteen;

  GobanController gobanController;

  GobanTheme _getThemeFromString(String themeStr) {
    GobanTheme theme = GobanTheme.defaultTheme();

    if (themeStr == 'book') {
      theme = GobanTheme.bookTheme();
    } else if (themeStr == 'jade') {
      theme = GobanTheme.jadeTheme();
    }

    return theme;
  }

  @override
  void initState() {
    gobanController = GobanController(
        boardSize: boardSize, gobanTheme: _getThemeFromString(gobanTheme));

    gobanController.gobanStream.stream.listen((Position pos) {
      var clickedPlayer = gobanController.getPlayerFromPosition(pos);
      if (clickedPlayer == Player.Empty) {
        var move = Move(player, pos);

        gobanController.addMove(move);

        setState(() {
          player = player == Player.Black ? Player.White : Player.Black;
        });
      }
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        gobanController.goban,
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Theme:',
              style: TextStyle(fontSize: 16),
            ),
            Container(
              margin: EdgeInsets.only(left: 10),
              child: DropdownButton<String>(
                value: gobanTheme,
                onChanged: (String theme) => setState(() {
                  gobanTheme = theme;
                  gobanController.setTheme(_getThemeFromString(gobanTheme));
                }),
                items: [
                  DropdownMenuItem(
                    child: Text('Default'),
                    value: 'default',
                  ),
                  DropdownMenuItem(
                    child: Text('Book'),
                    value: 'book',
                  ),
                  DropdownMenuItem(
                    child: Text('Jade'),
                    value: 'jade',
                  )
                ],
              ),
            ),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Size:',
              style: TextStyle(fontSize: 16),
            ),
            Container(
              margin: EdgeInsets.only(left: 10),
              child: DropdownButton<BoardSize>(
                value: boardSize,
                onChanged: (BoardSize size) => setState(() {
                  boardSize = size;
                  gobanController.setSize(boardSize);
                }),
                items: [
                  DropdownMenuItem(
                    child: Text('9x9'),
                    value: BoardSize.Nine,
                  ),
                  DropdownMenuItem(
                    child: Text('13x13'),
                    value: BoardSize.Thirteen,
                  ),
                  DropdownMenuItem(
                    child: Text('19x19'),
                    value: BoardSize.Nineteen,
                  )
                ],
              ),
            ),
          ],
        )
      ],
    ));
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  goban: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:goban/goban.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
9
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Nov 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0-dev <3.0.0
flutter 0.0.0
provider ^3.0.0+1 3.1.0+1
tuple ^1.0.2 1.0.3
Transitive dependencies
collection 1.14.11 1.14.12
matcher 0.12.6
meta 1.1.7 1.1.8
path 1.6.4
quiver 2.1.2+1
sky_engine 0.0.99
stack_trace 1.9.3
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test