Skip to content

Commit 927289f

Browse files
authored
Remove single view assumption from TestViewConfiguration (#122352)
Remove single view assumption from TestViewConfiguration
1 parent 4792297 commit 927289f

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ Future<void> main() async {
3131
await tester.pump(); // Start drawer animation
3232
await tester.pump(const Duration(seconds: 1)); // Complete drawer animation
3333

34-
final TestViewConfiguration big = TestViewConfiguration(
34+
final TestViewConfiguration big = TestViewConfiguration.fromView(
3535
size: const Size(360.0, 640.0),
36-
window: tester.view,
36+
view: tester.view,
3737
);
38-
final TestViewConfiguration small = TestViewConfiguration(
38+
final TestViewConfiguration small = TestViewConfiguration.fromView(
3939
size: const Size(355.0, 635.0),
40-
window: tester.view,
40+
view: tester.view,
4141
);
4242
final RenderView renderView = WidgetsBinding.instance.renderView;
4343
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmark;

packages/flutter_test/lib/src/binding.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,9 +1919,9 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
19191919

19201920
@override
19211921
ViewConfiguration createViewConfiguration() {
1922-
return TestViewConfiguration(
1922+
return TestViewConfiguration.fromView(
19231923
size: _surfaceSize ?? _kDefaultTestViewportSize,
1924-
window: window,
1924+
view: window,
19251925
);
19261926
}
19271927

@@ -1945,20 +1945,31 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
19451945
/// size is in logical pixels. The resulting ViewConfiguration maps the given
19461946
/// size onto the actual display using the [BoxFit.contain] algorithm.
19471947
class TestViewConfiguration extends ViewConfiguration {
1948-
/// Creates a [TestViewConfiguration] with the given size. Defaults to 800x600.
1948+
/// Deprecated. Will be removed in a future version of Flutter.
1949+
///
1950+
/// This property has been deprecated to prepare for Flutter's upcoming
1951+
/// support for multiple views and multiple windows.
19491952
///
1950-
/// If a [window] instance is not provided it defaults to [ui.window].
1953+
/// Use [TestViewConfiguration.fromView] instead.
1954+
@Deprecated(
1955+
'Use TestViewConfiguration.fromView instead. '
1956+
'Deprecated to prepare for the upcoming multi-window support. '
1957+
'This feature was deprecated after v3.7.0-32.0.pre.'
1958+
)
19511959
factory TestViewConfiguration({
19521960
Size size = _kDefaultTestViewportSize,
19531961
ui.FlutterView? window,
19541962
}) {
1955-
return TestViewConfiguration._(size, window ?? ui.window);
1963+
return TestViewConfiguration.fromView(size: size, view: window ?? ui.window);
19561964
}
19571965

1958-
TestViewConfiguration._(Size size, ui.FlutterView window)
1959-
: _paintMatrix = _getMatrix(size, window.devicePixelRatio, window),
1960-
_hitTestMatrix = _getMatrix(size, 1.0, window),
1961-
super(size: size, devicePixelRatio: window.devicePixelRatio);
1966+
/// Creates a [TestViewConfiguration] with the given size and view.
1967+
///
1968+
/// The [size] defaults to 800x600.
1969+
TestViewConfiguration.fromView({required ui.FlutterView view, super.size = _kDefaultTestViewportSize})
1970+
: _paintMatrix = _getMatrix(size, view.devicePixelRatio, view),
1971+
_hitTestMatrix = _getMatrix(size, 1.0, view),
1972+
super(devicePixelRatio: view.devicePixelRatio);
19621973

19631974
static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.FlutterView window) {
19641975
final double inverseRatio = devicePixelRatio / window.devicePixelRatio;

packages/integration_test/lib/integration_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
120120
ViewConfiguration createViewConfiguration() {
121121
final double devicePixelRatio = window.devicePixelRatio;
122122
final Size size = _surfaceSize ?? window.physicalSize / devicePixelRatio;
123-
return TestViewConfiguration(
123+
return TestViewConfiguration.fromView(
124124
size: size,
125-
window: window,
125+
view: window,
126126
);
127127
}
128128

0 commit comments

Comments
 (0)