mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
This reverts commit 3ab799bbc9
.
This commit is contained in:
parent
27d1e5892f
commit
dbc8826816
@ -6304,7 +6304,6 @@ class MultiChildRenderObjectElement extends RenderObjectElement {
|
|||||||
void update(MultiChildRenderObjectWidget newWidget) {
|
void update(MultiChildRenderObjectWidget newWidget) {
|
||||||
super.update(newWidget);
|
super.update(newWidget);
|
||||||
assert(widget == newWidget);
|
assert(widget == newWidget);
|
||||||
assert(!debugChildrenHaveDuplicateKeys(widget, widget.children));
|
|
||||||
_children = updateChildren(_children, widget.children, forgottenChildren: _forgottenChildren);
|
_children = updateChildren(_children, widget.children, forgottenChildren: _forgottenChildren);
|
||||||
_forgottenChildren.clear();
|
_forgottenChildren.clear();
|
||||||
}
|
}
|
||||||
|
@ -512,9 +512,11 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
exception.toString(),
|
exception.toString(),
|
||||||
equalsIgnoringHashCodes(
|
equalsIgnoringHashCodes(
|
||||||
'Duplicate keys found.\n'
|
'Multiple widgets used the same GlobalKey.\n'
|
||||||
'If multiple keyed nodes exist as children of another node, they must have unique keys.\n'
|
'The key [GlobalKey#00000 problematic] was used by 2 widgets:\n'
|
||||||
'Stack(alignment: AlignmentDirectional.topStart, textDirection: ltr, fit: loose) has multiple children with key [GlobalKey#00000 problematic].'
|
' SizedBox-[GlobalKey#00000 problematic]\n'
|
||||||
|
' Placeholder-[GlobalKey#00000 problematic]\n'
|
||||||
|
'A GlobalKey can only be specified on one widget at a time in the widget tree.',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -539,9 +541,11 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
exception.toString(),
|
exception.toString(),
|
||||||
equalsIgnoringHashCodes(
|
equalsIgnoringHashCodes(
|
||||||
'Duplicate keys found.\n'
|
'Multiple widgets used the same GlobalKey.\n'
|
||||||
'If multiple keyed nodes exist as children of another node, they must have unique keys.\n'
|
'The key [GlobalKey#00000 problematic] was used by 2 widgets:\n'
|
||||||
'Stack(alignment: AlignmentDirectional.topStart, textDirection: ltr, fit: loose) has multiple children with key [GlobalKey#00000 problematic].'
|
' Container-[GlobalKey#00000 problematic]\n'
|
||||||
|
' Placeholder-[GlobalKey#00000 problematic]\n'
|
||||||
|
'A GlobalKey can only be specified on one widget at a time in the widget tree.',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -58,57 +58,6 @@ void main() {
|
|||||||
<String>['0', '6', '7', '8', '1', '2', '3', '4', '5'],
|
<String>['0', '6', '7', '8', '1', '2', '3', '4', '5'],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Building a new MultiChildRenderObjectElement with children having duplicated keys throws', (WidgetTester tester) async {
|
|
||||||
const ValueKey<int> duplicatedKey = ValueKey<int>(1);
|
|
||||||
|
|
||||||
await tester.pumpWidget(Column(
|
|
||||||
children: const <Widget>[
|
|
||||||
Text('Text 1', textDirection: TextDirection.ltr, key: duplicatedKey),
|
|
||||||
Text('Text 2', textDirection: TextDirection.ltr, key: duplicatedKey),
|
|
||||||
],
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(
|
|
||||||
tester.takeException(),
|
|
||||||
isA<FlutterError>().having(
|
|
||||||
(FlutterError error) => error.message,
|
|
||||||
'error.message',
|
|
||||||
startsWith('Duplicate keys found.'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('Updating a MultiChildRenderObjectElement to have children with duplicated keys throws', (WidgetTester tester) async {
|
|
||||||
// Regression test for https://github.com/flutter/flutter/issues/81541
|
|
||||||
|
|
||||||
const ValueKey<int> key1 = ValueKey<int>(1);
|
|
||||||
const ValueKey<int> key2 = ValueKey<int>(2);
|
|
||||||
|
|
||||||
Future<void> _buildWithKey(Key key) {
|
|
||||||
return tester.pumpWidget(Column(
|
|
||||||
children: <Widget>[
|
|
||||||
const Text('Text 1', textDirection: TextDirection.ltr, key: key1),
|
|
||||||
Text('Text 2', textDirection: TextDirection.ltr, key: key),
|
|
||||||
],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initial build with two different keys.
|
|
||||||
await _buildWithKey(key2);
|
|
||||||
expect(tester.takeException(), isNull);
|
|
||||||
|
|
||||||
// Subsequent build with duplicated keys.
|
|
||||||
await _buildWithKey(key1);
|
|
||||||
expect(
|
|
||||||
tester.takeException(),
|
|
||||||
isA<FlutterError>().having(
|
|
||||||
(FlutterError error) => error.message,
|
|
||||||
'error.message',
|
|
||||||
startsWith('Duplicate keys found.'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not use tester.renderObjectList(find.byType(RenderParagraph). That returns
|
// Do not use tester.renderObjectList(find.byType(RenderParagraph). That returns
|
||||||
|
Loading…
Reference in New Issue
Block a user