Use PlatformDispatcher.instance over window where possible (#99496)
This commit is contained in:
committed by
GitHub
parent
a4aeb77876
commit
7f2c1cd772
@@ -262,7 +262,7 @@ abstract class SceneBuilderRecorder extends Recorder {
|
||||
final Completer<Profile> profileCompleter = Completer<Profile>();
|
||||
_profile = Profile(name: name);
|
||||
|
||||
window.onBeginFrame = (_) {
|
||||
PlatformDispatcher.instance.onBeginFrame = (_) {
|
||||
try {
|
||||
startMeasureFrame(profile!);
|
||||
onBeginFrame();
|
||||
@@ -271,7 +271,7 @@ abstract class SceneBuilderRecorder extends Recorder {
|
||||
rethrow;
|
||||
}
|
||||
};
|
||||
window.onDrawFrame = () {
|
||||
PlatformDispatcher.instance.onDrawFrame = () {
|
||||
try {
|
||||
_profile!.record('drawFrameDuration', () {
|
||||
final SceneBuilder sceneBuilder = SceneBuilder();
|
||||
@@ -286,7 +286,7 @@ abstract class SceneBuilderRecorder extends Recorder {
|
||||
endMeasureFrame();
|
||||
|
||||
if (shouldContinue()) {
|
||||
window.scheduleFrame();
|
||||
PlatformDispatcher.instance.scheduleFrame();
|
||||
} else {
|
||||
profileCompleter.complete(_profile);
|
||||
}
|
||||
@@ -295,7 +295,7 @@ abstract class SceneBuilderRecorder extends Recorder {
|
||||
rethrow;
|
||||
}
|
||||
};
|
||||
window.scheduleFrame();
|
||||
PlatformDispatcher.instance.scheduleFrame();
|
||||
return profileCompleter.future;
|
||||
}
|
||||
}
|
||||
@@ -403,7 +403,7 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder {
|
||||
profile!.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed, reported: true);
|
||||
|
||||
if (shouldContinue()) {
|
||||
window.scheduleFrame();
|
||||
PlatformDispatcher.instance.scheduleFrame();
|
||||
} else {
|
||||
for (final VoidCallback fn in _didStopCallbacks)
|
||||
fn();
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui show window;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:stocks/main.dart' as stocks;
|
||||
@@ -61,8 +59,8 @@ void main() {
|
||||
expect(find.text('Account Balance'), findsNothing);
|
||||
|
||||
// drag the drawer out
|
||||
final Offset left = Offset(0.0, (ui.window.physicalSize / ui.window.devicePixelRatio).height / 2.0);
|
||||
final Offset right = Offset((ui.window.physicalSize / ui.window.devicePixelRatio).width, left.dy);
|
||||
final Offset left = Offset(0.0, (WidgetsBinding.instance.window.physicalSize / WidgetsBinding.instance.window.devicePixelRatio).height / 2.0);
|
||||
final Offset right = Offset((WidgetsBinding.instance.window.physicalSize / WidgetsBinding.instance.window.devicePixelRatio).width, left.dy);
|
||||
final TestGesture gesture = await tester.startGesture(left);
|
||||
await tester.pump();
|
||||
await gesture.moveTo(right);
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -14,8 +12,8 @@ VoidCallback? originalSemanticsListener;
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
// Disconnects semantics listener for testing purposes.
|
||||
originalSemanticsListener = ui.window.onSemanticsEnabledChanged;
|
||||
ui.window.onSemanticsEnabledChanged = null;
|
||||
originalSemanticsListener = WidgetsBinding.instance.platformDispatcher.onSemanticsEnabledChanged;
|
||||
RendererBinding.instance.platformDispatcher.onSemanticsEnabledChanged = null;
|
||||
RendererBinding.instance.setSemanticsEnabled(false);
|
||||
// If the test passes, LifeCycleSpy will rewire the semantics listener back.
|
||||
runApp(const LifeCycleSpy());
|
||||
@@ -71,7 +69,7 @@ class _LifeCycleSpyState extends State<LifeCycleSpy> with WidgetsBindingObserver
|
||||
if (const ListEquality<AppLifecycleState?>().equals(_actualLifeCycleSequence, _expectedLifeCycleSequence)) {
|
||||
// Rewires the semantics harness if test passes.
|
||||
RendererBinding.instance.setSemanticsEnabled(true);
|
||||
ui.window.onSemanticsEnabledChanged = originalSemanticsListener;
|
||||
RendererBinding.instance.platformDispatcher.onSemanticsEnabledChanged = originalSemanticsListener;
|
||||
}
|
||||
return const MaterialApp(
|
||||
title: 'Flutter View',
|
||||
|
||||
@@ -10,6 +10,6 @@ import 'package:flutter_driver/driver_extension.dart';
|
||||
|
||||
void main() {
|
||||
enableFlutterDriverExtension(handler: (String? message) async {
|
||||
return ui.window.defaultRouteName;
|
||||
return ui.PlatformDispatcher.instance.defaultRouteName;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user