Commit e074af80 authored by Hans Muller's avatar Hans Muller

Merge pull request #2837 from HansMuller/overscroll

Fixed VirtualViewport child key assignment
parents 839334a5 ff424196
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:collection';
import 'framework.dart';
import 'media_query.dart';
......@@ -22,3 +24,23 @@ bool debugCheckHasMediaQuery(BuildContext context) {
});
return true;
}
bool debugHasDuplicateKeys(Widget parent, Iterable<Widget> children) {
assert(() {
Set<Key> keySet = new HashSet<Key>();
for (Widget child in children) {
assert(child != null);
if (child.key == null)
continue;
if (!keySet.add(child.key)) {
throw new FlutterError(
'Duplicate keys found.\n'
'If multiple keyed nodes exist as children of another node, they must have unique keys.\n'
'$parent has multiple children with key "${child.key}".'
);
}
}
return true;
});
return false;
}
......@@ -5,6 +5,8 @@
import 'dart:async';
import 'dart:collection';
import 'debug.dart';
import 'package:flutter/rendering.dart';
export 'dart:ui' show hashValues, hashList;
......@@ -1935,7 +1937,7 @@ class SingleChildRenderObjectElement extends RenderObjectElement {
/// Instantiation of RenderObjectWidgets that can have a list of children
class MultiChildRenderObjectElement extends RenderObjectElement {
MultiChildRenderObjectElement(MultiChildRenderObjectWidget widget) : super(widget) {
assert(!_debugHasDuplicateIds());
assert(!debugHasDuplicateKeys(widget, widget.children));
}
@override
......@@ -1968,24 +1970,6 @@ class MultiChildRenderObjectElement extends RenderObjectElement {
assert(renderObject == this.renderObject);
}
bool _debugHasDuplicateIds() {
Set<Key> idSet = new HashSet<Key>();
for (Widget child in widget.children) {
assert(child != null);
if (child.key == null)
continue; // when these nodes are reordered, we just reassign the data
if (!idSet.add(child.key)) {
throw new FlutterError(
'Duplicate keys found.\n'
'If multiple keyed nodes exist as children of another node, they must have unique keys.\n'
'$widget has multiple children with key "${child.key}".'
);
}
}
return false;
}
@override
void visitChildren(ElementVisitor visitor) {
for (Element child in _children) {
......
......@@ -5,6 +5,7 @@
import 'dart:math' as math;
import 'basic.dart';
import 'debug.dart';
import 'framework.dart';
import 'package:flutter/rendering.dart';
......@@ -169,9 +170,10 @@ abstract class VirtualViewportElement extends RenderObjectElement {
for (int i = 0; i < count; ++i) {
int childIndex = base + i;
Widget child = _widgetProvider.getChild(childIndex);
Key key = new ValueKey<Key>(child.key) ?? new ValueKey<int>(childIndex);
Key key = child.key != null ? new ValueKey<Key>(child.key) : new ValueKey<int>(childIndex);
newWidgets[i] = new RepaintBoundary(key: key, child: child);
}
assert(!debugHasDuplicateKeys(widget, newWidgets));
_materializedChildren = updateChildren(_materializedChildren, newWidgets);
}
......
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