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 { ...@@ -224,9 +224,12 @@ class _DragAvatar {
} }
void rebuild(BuildContext context) { void rebuild(BuildContext context) {
_entry?.remove(); if (_entry == null) {
_entry = new OverlayEntry(child: _build(context)); _entry = new OverlayEntry(child: _build(context));
Navigator.of(context).overlay.insert(_entry); Navigator.of(context).overlay.insert(_entry);
} else {
_entry.child = _build(context);
}
} }
DragTargetState _getDragTarget(List<HitTestEntry> path) { DragTargetState _getDragTarget(List<HitTestEntry> path) {
...@@ -251,6 +254,7 @@ class _DragAvatar { ...@@ -251,6 +254,7 @@ class _DragAvatar {
_activeTarget = null; _activeTarget = null;
_activeTargetWillAcceptDrop = false; _activeTargetWillAcceptDrop = false;
_entry.remove(); _entry.remove();
_entry = null;
if (onDragFinished != null) if (onDragFinished != null)
onDragFinished(); onDragFinished();
} }
......
...@@ -7,19 +7,26 @@ import 'framework.dart'; ...@@ -7,19 +7,26 @@ import 'framework.dart';
class OverlayEntry { class OverlayEntry {
OverlayEntry({ OverlayEntry({
this.child, Widget child,
bool opaque: false 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 get opaque => _opaque;
bool _opaque; bool _opaque;
void set opaque(bool value) { void set opaque (bool value) {
if (_opaque == value) if (_opaque == value)
return; return;
_opaque = value; _opaque = value;
_state?.setState(() {}); _rebuild();
} }
OverlayState _state; OverlayState _state;
...@@ -29,6 +36,10 @@ class OverlayEntry { ...@@ -29,6 +36,10 @@ class OverlayEntry {
_state?._remove(this); _state?._remove(this);
_state = null; _state = null;
} }
void _rebuild() {
_state?.setState(() {});
}
} }
class Overlay extends StatefulComponent { 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