Commit ff424196 authored by Hans Muller's avatar Hans Muller

Fixed VirtualViewport child key assignment

parent 839334a5
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:collection';
import 'framework.dart'; import 'framework.dart';
import 'media_query.dart'; import 'media_query.dart';
...@@ -22,3 +24,23 @@ bool debugCheckHasMediaQuery(BuildContext context) { ...@@ -22,3 +24,23 @@ bool debugCheckHasMediaQuery(BuildContext context) {
}); });
return true; 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 @@ ...@@ -5,6 +5,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:collection'; import 'dart:collection';
import 'debug.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
export 'dart:ui' show hashValues, hashList; export 'dart:ui' show hashValues, hashList;
...@@ -1935,7 +1937,7 @@ class SingleChildRenderObjectElement extends RenderObjectElement { ...@@ -1935,7 +1937,7 @@ class SingleChildRenderObjectElement extends RenderObjectElement {
/// Instantiation of RenderObjectWidgets that can have a list of children /// Instantiation of RenderObjectWidgets that can have a list of children
class MultiChildRenderObjectElement extends RenderObjectElement { class MultiChildRenderObjectElement extends RenderObjectElement {
MultiChildRenderObjectElement(MultiChildRenderObjectWidget widget) : super(widget) { MultiChildRenderObjectElement(MultiChildRenderObjectWidget widget) : super(widget) {
assert(!_debugHasDuplicateIds()); assert(!debugHasDuplicateKeys(widget, widget.children));
} }
@override @override
...@@ -1968,24 +1970,6 @@ class MultiChildRenderObjectElement extends RenderObjectElement { ...@@ -1968,24 +1970,6 @@ class MultiChildRenderObjectElement extends RenderObjectElement {
assert(renderObject == this.renderObject); 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 @override
void visitChildren(ElementVisitor visitor) { void visitChildren(ElementVisitor visitor) {
for (Element child in _children) { for (Element child in _children) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'basic.dart'; import 'basic.dart';
import 'debug.dart';
import 'framework.dart'; import 'framework.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -169,9 +170,10 @@ abstract class VirtualViewportElement extends RenderObjectElement { ...@@ -169,9 +170,10 @@ abstract class VirtualViewportElement extends RenderObjectElement {
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
int childIndex = base + i; int childIndex = base + i;
Widget child = _widgetProvider.getChild(childIndex); 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); newWidgets[i] = new RepaintBoundary(key: key, child: child);
} }
assert(!debugHasDuplicateKeys(widget, newWidgets));
_materializedChildren = updateChildren(_materializedChildren, 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