treemap 0.4.0 copy "treemap: ^0.4.0" to clipboard
treemap: ^0.4.0 copied to clipboard

A simple Dart implementation of treemap.

example/lib/main.dart

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:treemap/treemap.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: 'Flutter Demo',
      theme: ThemeData(
        brightness: Brightness.dark,
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

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

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

class _MyHomePageState extends State<MyHomePage> {
  List<TreeNode> childNode = [];

  @override
  void initState() {
    super.initState();
    _addNewNode();
  }

  _addNewNode() {
    setState(() {
      final node = TreeNode.leaf(
        value: max(1, Random().nextInt(10)),
        margin: EdgeInsets.all(5),
        options: TreeNodeOptions(
          color: () {
            Random random = Random();
            return Colors.primaries[random.nextInt(Colors.primaries.length)];
          }(),
        ),
      );
      node.options?.onTap = () {
        setState(() {
          node.value += 1;
          // childNode.remove(node);
        });
      };
      childNode.add(node);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          color: Colors.red,
          width: 425,
          height: 425,
          child: TreeMapLayout(
            duration: Duration(milliseconds: 500),
            tile: Binary(),
            children: [
              TreeNode.node(
                padding: EdgeInsets.all(20),
                margin: EdgeInsets.all(5),
                children: childNode,
                options: TreeNodeOptions(
                  color: Colors.amber,
                ),
              ),
              TreeNode.node(
                padding: EdgeInsets.all(20),
                margin: EdgeInsets.all(5),
                children: [TreeNode.leaf(value: 15)],
                options: TreeNodeOptions(
                  color: Colors.blue,
                ),
              ),
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Text("+"),
        onPressed: () {
          _addNewNode();
        },
      ),
    );
  }
}
7
likes
130
pub points
84%
popularity

Publisher

unverified uploader

A simple Dart implementation of treemap.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on treemap