hexagonal_grid 1.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

hexagonal_grid #

A hexagonal grid library for Dart 2 that uses axial coordinates and contains algorithms to build hex layouts. Inspired and implemented from https://www.redblobgames.com/grids/hexagons/implementation.html

[1.0.5] - 03/01/2019

  • Bug fix for toSpiralHexLayout with a null or empty list

[1.0.4] - 01/16/2019

  • General clean up and make package available for Dart projects, not just Flutter

[1.0.0] - 01/16/2019

  • Packagized this hex grid code that I have been using in my own projects so other projects and packages can use it. Contains implementations for Hex via axial coordinates as well as layouts and an algorithm to create a spiral out layout given a list.


import 'dart:math';

import 'package:hexagonal_grid/hexagonal_grid.dart';

class Example {
  void createOriginHexWithLayout() {
    //Origin hex where q = 0, and r = 0 (axial coordinates)
    final Hex originHex = Hex(0, 0);

    //Arbitrary sizes and layout origins to help construct the HexLayout
    final Point size = Point(2, 2);
    final Point hexLayoutOrigin = Point(5, 5);

    //Create a flat HexLayout
    final HexLayout hexLayout = HexLayout.orientFlat(size, hexLayoutOrigin);

    //Transpose the axial coordinate Hex onto the HexLayout to get a pixel
    // representation of that Hex
    final Point hexToPixel = originHex.toPixel(hexLayout);

  void createNeighbors() {
    //Origin hex where q = 0, and r = 0 (axial coordinates)
    final Hex originHex = Hex(0, 0);

    //Iterate through each possible direction of a hex (six of them) and get the
    // neighbor for each. Then print them out.
    for (int d = 0; d < Hex.directions.length; d++) {
      Hex neighborHex = originHex.neighbor(d);

Use this package as a library

1. Depend on it

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

  hexagonal_grid: ^1.0.5

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or 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:hexagonal_grid/hexagonal_grid.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/hexagonal_grid.dart. (-1.99 points)

Analysis of lib/hexagonal_grid.dart reported 4 hints:

line 52 col 27: Unnecessary new keyword.

line 145 col 7: Unnecessary new keyword.

line 149 col 23: Unnecessary new keyword.

line 154 col 23: Unnecessary new keyword.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
Dev dependencies
test ^1.5.1