Commit ff1b1318 authored by Adam Barth's avatar Adam Barth

Teach OverlayEntry how to rebuild in place

This patch makes it so drag-and-drop doesn't thrash the overlay list.
parent 05f19cfd
......@@ -224,9 +224,12 @@ class _DragAvatar {
}
void rebuild(BuildContext context) {
_entry?.remove();
if (_entry == null) {
_entry = new OverlayEntry(child: _build(context));
Navigator.of(context).overlay.insert(_entry);
} else {
_entry.child = _build(context);
}
}
DragTargetState _getDragTarget(List<HitTestEntry> path) {
......@@ -251,6 +254,7 @@ class _DragAvatar {
_activeTarget = null;
_activeTargetWillAcceptDrop = false;
_entry.remove();
_entry = null;
if (onDragFinished != null)
onDragFinished();
}
......
......@@ -7,19 +7,26 @@ import 'framework.dart';
class OverlayEntry {
OverlayEntry({
this.child,
Widget child,
bool opaque: false
}) : _opaque = opaque;
}) : _child = child, _opaque = opaque;
final Widget child;
Widget get child => _child;
Widget _child;
void set child (Widget value) {
if (_child == value)
return;
_child = value;
_rebuild();
}
bool get opaque => _opaque;
bool _opaque;
void set opaque(bool value) {
void set opaque (bool value) {
if (_opaque == value)
return;
_opaque = value;
_state?.setState(() {});
_rebuild();
}
OverlayState _state;
......@@ -29,6 +36,10 @@ class OverlayEntry {
_state?._remove(this);
_state = null;
}
void _rebuild() {
_state?.setState(() {});
}
}
class Overlay extends StatefulComponent {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment