【问题标题】:Is there a way to create flowcharts or trunks in flutter?有没有办法在颤动中创建流程图或主干?
【发布时间】:2019-07-30 06:35:47
【问题描述】:

有没有办法在颤振中创建流程图或主干? 也许您对我如何构建它有想法或示例。我目前的尝试是将元素拖放到地方,这也有效。但是现在我遇到了无法将元素相互连接的问题。我已经尝试过失败的CustomPainter baer

class _main extends State<Main> {

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
          title: Text('Stammbaum'),
          backgroundColor: Colors.pink),      
      body: Column(
        children: <Widget>[

          Container(
            decoration: BoxDecoration(
              border:Border.all(color: Colors.black, width: 0.3)
            ),
            child: Row(       

            children: <Widget>[


              Padding(
                padding: EdgeInsets.all(10),
                child:Draggable(
                  data: 1,
                  child: Icon(Icons.access_alarm),
                  feedback: Icon(Icons.access_alarm),
                  childWhenDragging: Icon(Icons.access_alarm),
                ), 
              ),
              Padding(
                padding: EdgeInsets.all(10),
                child: Draggable(
                data: 2,
                child: Icon(Icons.accessibility_new),
                feedback: Icon(Icons.accessibility_new),
                childWhenDragging: Icon(Icons.accessibility_new),
              ),  
              ),
              Padding(
                padding: EdgeInsets.all(10),
                child: Draggable(
                  data: 3,
                  child: Icon(Icons.delete),
                  feedback: Icon(Icons.delete),
                  childWhenDragging: Icon(Icons.delete),
                ),  
              ), 
            ],
          ),    
        ),   
          Column(
            children: <Widget>[
              ContentRow(),
              ContentRow(),
              ContentRow(),
              ContentRow(),
              ContentRow(),
              ContentRow(),
              ContentRow(),
              ContentRow(),
              ContentRow(),
            ],
          )             
        ],
      ),
    );
  } 
}

class ContentRow extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Content(),
        Content(),
        Content(),
        Content(),
        Content(),
        Content(),
        Content(),

      ],
    );
  }
}

  var p1;
  var p2;

class Content extends StatelessWidget{
  bool firstTap = true;
  var p1;
  var p2;

  @override
  Widget build(BuildContext context) {
      bool accepted = false;
      Icon dataIcon ;

   _onTapDown(TapDownDetails details) {
    var x = details.globalPosition.dx;
    var y = details.globalPosition.dy;
    if(firstTap ){
      p1 = Offset(x, y);
      firstTap = false;
    }else{
      p2 = Offset(x, y);
      firstTap=true;
      print("$p1 , $p2");

    }   
  }

    return GestureDetector(
       onTapDown: (TapDownDetails details) => _onTapDown(details),
      child:Container(

            width: 50.0,
            height: 50.0,              
            child: DragTarget(              
              builder: (context, List<int> candidateData, rejectedData) {
                print(candidateData);
                return accepted ? dataIcon : Container();
              },
              onWillAccept: (data) {
                return true;
              },
               onAccept: (data) {
               if(data==1){
                 accepted=true;
                  dataIcon = Icon(Icons.access_alarm);
               }
               if (data==2){
                 accepted=true;
                 dataIcon=Icon(Icons.accessibility_new);
               }
               if(data==3){
                 accepted=false;
                 dataIcon=null;
               }
              },              
            ),             
          ) ,
    ) ; 
  }
}

class MyPainter extends CustomPainter { //         <-- CustomPainter class
   @override
void paint(Canvas canvas, Size size) {
  final point1 = p1;
  final point2 =p2;
  final paint = Paint()
    ..color = Colors.black
    ..strokeWidth = 2;
  canvas.drawLine(point1, point2, paint);
}

  @override
  bool shouldRepaint(CustomPainter old) {
    return false;
  }
}

【问题讨论】:

  • 请发布您渲染的小部件的屏幕截图。

标签: flutter dart flowchart


【解决方案1】:

尝试使用 charts_flutter: ^0.8.1,,, 在 pub 中找到,不同图表也有详细示例

【讨论】:

    猜你喜欢
    • 2022-10-12
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 2020-11-06
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    相关资源
    最近更新 更多