Skip to content

Removing a draggable from the widget tree while it's being dragged leaves the feedback in the overlay. #6151

@apwilson

Description

@apwilson
// Copyright 2016 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/widgets.dart';

Future main() async {
  runApp(
    new Overlay(
      initialEntries: [
        new OverlayEntry(
          builder: (BuildContext context) => new Foo(),
        ),
      ],
    ),
  );
}

class Foo extends StatefulWidget {
  @override
  FooState createState() => new FooState();
}

class FooState extends State<Foo> {
  bool _includeDraggable = true;
  @override
  Widget build(BuildContext context) {
    Widget target = new Container(
      width: 100.0,
      height: 100.0,
      decoration: new BoxDecoration(
        backgroundColor: new Color(0xFF00FFFF),
      ),
    );
    Widget draggable = new Container(
      width: 100.0,
      height: 100.0,
      decoration: new BoxDecoration(
        backgroundColor: new Color(0xFFFFFF00),
      ),
    );
    List<Widget> stackChildren = [
      _includeDraggable
          ? new Draggable<int>(
              data: 1,
              dragAnchor: DragAnchor.pointer,
              maxSimultaneousDrags: 1,
              childWhenDragging: draggable,
              feedback: draggable,
              child: draggable,
            )
          : draggable,
      new DragTarget<int>(
        onWillAccept: (int data) {
          setState(() {
            _includeDraggable = false;
          });
          return true;
        },
        onAccept: (int data) {},
        builder: (
          BuildContext context,
          List<int> candidateData,
          List<dynamic> rejectedData,
        ) =>
            target,
      ),
    ];
    return new Row(
      children: stackChildren,
    );
  }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions