relations 0.0.3 copy "relations: ^0.0.3" to clipboard
relations: ^0.0.3 copied to clipboard

outdated

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)
    );
  }

}
3
likes
0
pub points
0%
popularity

Publisher

verified publisherdev.allround.net

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

Homepage

License

unknown (LICENSE)

Dependencies

bloc, cupertino_icons, flutter, flutter_bloc, rxdart, vector_math

More

Packages that depend on relations