relations 1.0.0
relations: ^1.0.0

Flutter package for drag or connect nodes, and for doing operations on them.

example/lib/main.dart

import "package:relations/relations.dart";
import "package:flutter/material.dart";

void main() {
  runApp(RelationsTest());
}

class RelationsTest extends StatelessWidget {

  final Size stageSize = Size(4000, 4000);
  final double boxPadding = 10.0;

  Widget _getText({String title = "untitled", Color textColor = const Color.fromARGB(255, 30, 30, 30),}) {
    return 
      Text(
        title,
        style: TextStyle(
          color: textColor,
          decoration: TextDecoration.none
        )
      );
  }

  Widget _getBox({
      Color boxColor = Colors.lightBlue,
      Widget innerWidget
    }) {
    return 
      Container(
        color: boxColor, 
        padding: EdgeInsets.all(boxPadding),
        child: FittedBox(
          fit: BoxFit.contain, 

          child: innerWidget
        )
      );
  }

  Widget _getIcon({IconData iconData = Icons.favorite}) {
    return  
      Icon(
        iconData,
        color: Colors.red,
        size: 24.0
    );
  }

  List<GraphNode> _getNodes()  {

    const double size = 150; 
    /// if no size is provided to a node, the wrapper box sizes itself to match the child.
    return [
      GraphNode( 
        position: stageSize.center(Offset(0, 0)) - Offset(size/2.0, size/2.0),
        size: const Size(size, size), 
        widget: _getBox(
          boxColor: const Color.fromRGBO(167, 204, 237, 1.0),
          innerWidget: _getText(title: "node-1")
        ),
        data: "some data"
      ),
      GraphNode( 
        /// position: Offset(200,200),
        size: const Size(size, size), 
        widget: _getBox(
          boxColor: const Color.fromRGBO(167, 204, 237, 1.0),
          innerWidget: _getText(title: "node-3")
        ),
        data: "some data"
      ),
      GraphNode( 
        /// position: Offset(200,200),
        size: const Size(size, size), 
        widget: _getBox(
          boxColor: const Color.fromRGBO(167, 204, 237, 1.0),
          innerWidget: _getText(title: "node-3")
        ),
        data: "some data"
      ),
      GraphNode( 
        /// position: Offset(200,200),
        size: const Size(size, size), 
        widget: _getBox(
          boxColor: const Color.fromRGBO(167, 204, 237, 1.0),
          innerWidget: _getText(title: "node-4")
        ),
        data: "some data"
      ),
      GraphNode(
        position: Offset(200,200), 
        size: Size(size, size), 
        widget: _getBox(
          boxColor: const Color.fromRGBO(167, 204, 237, 1.0),
          innerWidget: _getText(title: "node-5")
        )
      ),
      GraphNode(
        position: Offset(200,200), 
        size: Size(size, size), 
        widget: _getBox(
          boxColor: const Color.fromRGBO(167, 204, 237, 1.0),
          innerWidget: _getIcon()
        )
      ),
    ];
  }

  void _onSave(Graph graph) {
    print(graph);
  }

  GraphNode _nodeProvider(Offset position) {
    String id = GraphNode.nextID;
    return 
      GraphNode(
        id: id,
        position: position,
        size: Size(150, 150),
        widget: _getBox(
          boxColor: const Color.fromRGBO(167, 204, 237, 1.0),
          innerWidget: _getText(title: "node-$id")
        )
      );
  }

  @override
  Widget build(BuildContext context) {

    StageConfig config = StageConfig(
      nodes: _getNodes(),
      onSave: _onSave,
      onAddNew: _nodeProvider,
      initialZoom: 0.4,
      stageSize: stageSize,
      theme: const StageTheme()
    );

    return MaterialApp(
      title: "Allround Relations",
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: StageWrapper(stageConfig: config)
    );
  }

}
2
likes
60
pub points
25%
popularity

Publisher

dev.allround.net

Flutter package for drag or connect nodes, and for doing operations on them.

Homepage

Documentation

API reference

License

MIT (LICENSE)

Dependencies

bloc, flutter, flutter_bloc, rxdart, vector_math

More

Packages that depend on relations