【问题标题】:How do i get the positions from Draggable on onDragCompleted?如何从 onDragCompleted 上的 Draggable 获取位置?
【发布时间】:2019-04-21 11:08:00
【问题描述】:

我如何才能完成拖动位置,以便我可以将视图移动到新位置。我很困惑dragtarget能否实现这个东西

  Positioned(
              child: Draggable(
                child: Text(
                  'Simple Text',
                ),
                feedback: Text(
                  'Simple Text',
                ),
                childWhenDragging: Text(
                  'Simple Text',
                ),
              ))

【问题讨论】:

    标签: flutter draggable


    【解决方案1】:

    从 statefulWidget 开始, 选择偏移位置 然后用新位置覆盖。

    Offset pos = Offset(50, 50);
    
    @override
    Widget build(BuildContext context) {
    
        return Stack(children: <Widget>[
             Positioned(
               top: pos.dy,
               left: pos.dx,
             child: Draggable(
               child: Text(
               'Simple Text',
              ),
             feedback: Text(
               'Simple Text',
              ),
             childWhenDragging: Text(
               'Simple Text',
              ),
             onDraggableCanceled: (view,offset){
               setState(() {
               pos=offset;
             });
             },
             data: ?,
        ),
        ),
    

    【讨论】:

      猜你喜欢
      • 2020-08-13
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多