Example #1
0
        public TextSelectionOverlay(TextEditingValue value                  = null,
                                    BuildContext context                    = null, Widget debugRequiredFor = null,
                                    LayerLink layerLink                     = null,
                                    RenderEditable renderObject             = null,
                                    TextSelectionControls selectionControls = null,
                                    TextSelectionDelegate selectionDelegate = null,
                                    DragStartBehavior dragStartBehavior     = DragStartBehavior.start)
        {
            D.assert(value != null);
            D.assert(context != null);
            this.context           = context;
            this.debugRequiredFor  = debugRequiredFor;
            this.layerLink         = layerLink;
            this.renderObject      = renderObject;
            this.selectionControls = selectionControls;
            this.selectionDelegate = selectionDelegate;
            this._value            = value;
            OverlayState overlay = Overlay.of(context);

            D.assert(overlay != null, () => $"No Overlay widget exists above {context}.\n" +
                     "Usually the Navigator created by WidgetsApp provides the overlay. Perhaps your " +
                     "app content was created above the Navigator with the WidgetsApp builder parameter.");
            this._toolbarController = new AnimationController(duration: fadeDuration, vsync: overlay);
            this.dragStartBehavior  = dragStartBehavior;
        }
Example #2
0
 public void showToolbar()
 {
     D.assert(this._toolbar == null);
     this._toolbar = new OverlayEntry(builder: this._buildToolbar);
     Overlay.of(this.context, debugRequiredFor: this.debugRequiredFor).insert(this._toolbar);
     this._toolbarController.forward(from: 0.0f);
 }
Example #3
0
 public void showToolbar()
 {
     D.assert(_toolbar == null);
     _toolbar = new OverlayEntry(builder: _buildToolbar);
     Overlay.of(context, rootOverlay: true, debugRequiredFor: debugRequiredFor).insert(_toolbar);
     _toolbarController.forward(from: 0.0f);
 }
Example #4
0
 public void showHandles()
 {
     D.assert(_handles == null);
     _handles = new List <OverlayEntry> {
         new OverlayEntry(builder: (BuildContext context) =>
                          _buildHandle(context, _TextSelectionHandlePosition.start)),
         new OverlayEntry(builder: (BuildContext context) =>
                          _buildHandle(context, _TextSelectionHandlePosition.end)),
     };
     Overlay.of(this.context, rootOverlay: true, debugRequiredFor: debugRequiredFor).insertAll(_handles);
 }
Example #5
0
 public void showHandles()
 {
     D.assert(this._handles == null);
     this._handles = new List <OverlayEntry> {
         new OverlayEntry(builder: (BuildContext context) =>
                          this._buildHandle(context, _TextSelectionHandlePosition.start)),
         new OverlayEntry(builder: (BuildContext context) =>
                          this._buildHandle(context, _TextSelectionHandlePosition.end)),
     };
     Overlay.of(this.context, debugRequiredFor: this.debugRequiredFor).insertAll(this._handles);
     this._handleController.forward(from: 0.0f);
 }
Example #6
0
        public override Widget build(BuildContext context)
        {
            D.assert(Overlay.of(context, debugRequiredFor: this.widget) != null);
            bool canDrag = this.widget.maxSimultaneousDrags == null ||
                           this._activeCount < this.widget.maxSimultaneousDrags;

            bool showChild = this._activeCount == 0 || this.widget.childWhenDragging == null;

            if (canDrag)
            {
                return(new Listener(
                           onPointerDown: this._routePointer,
                           child: showChild ? this.widget.child : this.widget.childWhenDragging
                           ));
            }

            return(new Listener(
                       child: showChild ? this.widget.child : this.widget.childWhenDragging));
        }
Example #7
0
        public TextSelectionOverlay(TextEditingValue value                  = null,
                                    BuildContext context                    = null, Widget debugRequiredFor = null,
                                    LayerLink layerLink                     = null,
                                    RenderEditable renderObject             = null,
                                    TextSelectionControls selectionControls = null,
                                    TextSelectionDelegate selectionDelegate = null)
        {
            D.assert(value != null);
            D.assert(context != null);
            this.context           = context;
            this.debugRequiredFor  = debugRequiredFor;
            this.layerLink         = layerLink;
            this.renderObject      = renderObject;
            this.selectionControls = selectionControls;
            this.selectionDelegate = selectionDelegate;
            this._value            = value;
            OverlayState overlay = Overlay.of(context);

            D.assert(overlay != null);
            this._handleController  = new AnimationController(duration: _fadeDuration, vsync: overlay);
            this._toolbarController = new AnimationController(duration: _fadeDuration, vsync: overlay);
        }
Example #8
0
        public TextSelectionOverlay(
            TextEditingValue value                  = null,
            BuildContext context                    = null,
            Widget debugRequiredFor                 = null,
            LayerLink toolbarLayerLink              = null,
            LayerLink startHandleLayerLink          = null,
            LayerLink endHandleLayerLink            = null,
            RenderEditable renderObject             = null,
            TextSelectionControls selectionControls = null,
            bool?handlesVisible = false,
            TextSelectionDelegate selectionDelegate = null,
            DragStartBehavior dragStartBehavior     = DragStartBehavior.start,
            VoidCallback onSelectionHandleTapped    = null)
        {
            D.assert(value != null);
            D.assert(context != null);
            D.assert(handlesVisible != null);
            _handlesVisible              = handlesVisible.Value;
            this.context                 = context;
            this.debugRequiredFor        = debugRequiredFor;
            this.toolbarLayerLink        = toolbarLayerLink;
            this.startHandleLayerLink    = startHandleLayerLink;
            this.endHandleLayerLink      = endHandleLayerLink;
            this.renderObject            = renderObject;
            this.selectionControls       = selectionControls;
            this.selectionDelegate       = selectionDelegate;
            this.onSelectionHandleTapped = onSelectionHandleTapped;
            _value = value;
            OverlayState overlay = Overlay.of(context, rootOverlay: true);

            D.assert(overlay != null, () => $"No Overlay widget exists above {context}.\n" +
                     "Usually the Navigator created by WidgetsApp provides the overlay. Perhaps your " +
                     "app content was created above the Navigator with the WidgetsApp builder parameter.");
            _toolbarController     = new AnimationController(duration: fadeDuration, vsync: overlay);
            this.dragStartBehavior = dragStartBehavior;
        }
Example #9
0
        _DragAvatar <T> _startDrag(Offset position)
        {
            if (this.widget.maxSimultaneousDrags != null &&
                this._activeCount >= this.widget.maxSimultaneousDrags)
            {
                return(null);
            }

            var dragStartPoint = Offset.zero;

            switch (this.widget.dragAnchor)
            {
            case DragAnchor.child:
                RenderBox renderObject = this.context.findRenderObject() as RenderBox;
                dragStartPoint = renderObject.globalToLocal(position);
                break;

            case DragAnchor.pointer:
                dragStartPoint = Offset.zero;
                break;
            }

            this.setState(() => { this._activeCount += 1; });

            _DragAvatar <T> avatar = new _DragAvatar <T>(
                overlayState: Overlay.of(this.context, debugRequiredFor: this.widget),
                data: this.widget.data,
                axis: this.widget.axis,
                initialPosition: position,
                dragStartPoint: dragStartPoint,
                feedback: this.widget.feedback,
                feedbackOffset: this.widget.feedbackOffset,
                onDragEnd: (Velocity velocity, Offset offset, bool wasAccepted) => {
                if (this.mounted)
                {
                    this.setState(() => { this._activeCount -= 1; });
                }
                else
                {
                    this._activeCount -= 1;
                    this._disposeRecognizerIfInactive();
                }

                if (this.mounted && this.widget.onDragEnd != null)
                {
                    this.widget.onDragEnd(new DraggableDetails(
                                              wasAccepted: wasAccepted,
                                              velocity: velocity,
                                              offset: offset
                                              ));
                }

                if (wasAccepted && this.widget.onDragCompleted != null)
                {
                    this.widget.onDragCompleted();
                }

                if (!wasAccepted && this.widget.onDraggableCanceled != null)
                {
                    this.widget.onDraggableCanceled(velocity, offset);
                }
            }
                );

            if (this.widget.onDragStarted != null)
            {
                this.widget.onDragStarted();
            }

            return(avatar);
        }