[flutter] Allow ViewCollection to start empty. (#140532)

This enables multi-view apps to start with zero views.
This commit is contained in:
David Iglesias
2024-01-02 16:22:52 -08:00
committed by GitHub
parent 3ac2dba58d
commit 6b4f0d5753
3 changed files with 5 additions and 7 deletions

View File

@@ -475,9 +475,7 @@ class _MultiChildComponentWidget extends Widget {
/// * [WidgetsBinding] for an explanation of rendering and non-rendering zones.
class ViewCollection extends _MultiChildComponentWidget {
/// Creates a [ViewCollection] widget.
///
/// The provided list of [views] must contain at least one widget.
const ViewCollection({super.key, required super.views}) : assert(views.length > 0);
const ViewCollection({super.key, required super.views});
/// The [View] descendants of this widget.
///

View File

@@ -293,8 +293,8 @@ void main() {
testWidgets('ViewCollection cannot have render object widgets as children', (WidgetTester tester) async {
await pumpWidgetWithoutViewWrapper(
tester: tester,
widget: ViewCollection(
views: const <Widget>[
widget: const ViewCollection(
views: <Widget>[
ColoredBox(color: Colors.red),
],
),

View File

@@ -140,8 +140,8 @@ void main() {
);
});
testWidgets('ViewCollection must have one view', (WidgetTester tester) async {
expect(() => ViewCollection(views: const <Widget>[]), throwsAssertionError);
testWidgets('ViewCollection may start with zero views', (WidgetTester tester) async {
expect(() => const ViewCollection(views: <Widget>[]), returnsNormally);
});
testWidgets('ViewAnchor.child does not see surrounding view', (WidgetTester tester) async {