flutter_flutter/packages/flutter/test/widgets/multi_view_binding_test.dart
auto-submit[bot] 114261a63a
Reverts "Add runWidget to bootstrap a widget tree without a default View" (#142339)
Reverts flutter/flutter#141484
Initiated by: eliasyishak
This change reverts the following previous change:
Original Description:
The existing `runApp` bootstraps the widget tree and renders the provided widget into the default view (which is currently the implicit View from `PlatformDispatcher.implicitView` and - in the future - may be a default-created window). Apps, that want more control over the View they are rendered in, need a new way to bootstrap the widget tree: `runWidget`. It does not make any assumptions about the View the provided widget is rendered into. Instead, it is up to the caller to include a View widget in the provided widget tree that specifies where content should be rendered. In the future, this may enable developers to create a custom window for their app instead of relying on the default-created one.
2024-01-26 21:06:27 +00:00

40 lines
1.4 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('runApp uses deprecated pipelineOwner and renderView', (WidgetTester tester) async {
runApp(const SizedBox());
final RenderObject renderObject = tester.renderObject(find.byType(SizedBox));
RenderObject parent = renderObject;
while (parent.parent != null) {
parent = parent.parent!;
}
expect(parent, isA<RenderView>());
expect(parent, equals(tester.binding.renderView));
expect(renderObject.owner, equals(tester.binding.pipelineOwner));
});
testWidgets('can manually attach RootWidget to build owner', (WidgetTester tester) async {
expect(find.byType(ColoredBox), findsNothing);
final RootWidget rootWidget = RootWidget(
child: View(
view: tester.view,
child: const ColoredBox(color: Colors.orange),
),
);
tester.binding.attachToBuildOwner(rootWidget);
await tester.pump();
expect(find.byType(ColoredBox), findsOneWidget);
expect(tester.binding.rootElement!.widget, equals(rootWidget));
expect(tester.element(find.byType(ColoredBox)).owner, equals(tester.binding.buildOwner));
});
}