Teach OverlayEntry how to rebuild in place

This patch makes it so drag-and-drop doesn't thrash the overlay list.
This commit is contained in:
Adam Barth
2015-10-29 23:34:05 -07:00
parent 05f19cfd44
commit ff1b131814
2 changed files with 23 additions and 8 deletions

View File

@@ -224,9 +224,12 @@ class _DragAvatar {
}
void rebuild(BuildContext context) {
_entry?.remove();
_entry = new OverlayEntry(child: _build(context));
Navigator.of(context).overlay.insert(_entry);
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();
}

View File

@@ -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 {