node_tree 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 49

node_tree #

An unbalanced tree of arbitrary but limitable breadth and depth. Supports random and asynchronous generation.

Node children are kept in a HashMap instead of a list to support arbitrary placement.

"Breadth" (maxBreadth) here refers to the number of children per node, not to the tree itself.

[0.1.1] - November 4, 2018

  • Fix missing import.

[0.1.0] - October 30, 2018

  • First release.

example/main.dart

import 'dart:async';
import 'package:node_tree/node_tree.dart';

void main() async {
  // Number generator.
  Future<int> gen(int i) async => i + 1;

  print('Manual creation.');
  final tree = Tree<String>('a');
  final b = tree.root.add('b');
  final c = tree.root.add('c');
  b..add('d')..add('e');
  c..add('f')..add('g');
  tree.addRandom('x');
  print(tree.toString());

  print('10 random nodes.');
  print((await Tree.generate((i) async => i < 10 ? i + 1 : null))
      .toString(includePosition: true));
  print(
      (await Tree.generate(gen, maxNodes: 10)).toString(includePosition: true));

  print('Generated, depth-first.');
  print((await Tree.generate(gen, maxNodes: 10, depthFirst: true, maxDepth: 2))
      .toString(depthFirst: true));

  print('Generated, breadth-first.');
  print(
      await Tree.generate(gen, maxNodes: 10, depthFirst: false, maxBreadth: 2));

  print('Filled, depth first.');
  print((await Tree.generate(gen, maxBreadth: 2, maxDepth: 3, depthFirst: true))
      .toString(depthFirst: true));
}

Use this package as a library

1. Depend on it

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


dependencies:
  node_tree: ^0.1.1

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:node_tree/node_tree.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
1
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:node_tree/node_tree.dart.

Health suggestions

Fix lib/src/tree.dart. (-3.45 points)

Analysis of lib/src/tree.dart reported 7 hints, including:

line 19 col 26: Use = to separate a named parameter from its default value.

line 67 col 72: DO use curly braces for all flow control structures.

line 74 col 46: Use = to separate a named parameter from its default value.

line 74 col 69: Use = to separate a named parameter from its default value.

line 83 col 35: Use = to separate a named parameter from its default value.

Fix lib/src/node.dart. (-1 points)

Analysis of lib/src/node.dart reported 2 hints:

line 78 col 27: Use = to separate a named parameter from its default value.

line 78 col 50: Use = to separate a named parameter from its default value.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.0.0