Unverified Commit 428cafad authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] migrate some files to null safety (#110354)

parent 8a40c7de
......@@ -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:async';
import 'package:meta/meta.dart';
......
......@@ -290,9 +290,9 @@ class FlutterDriverService extends DriverService {
}) async {
if (writeSkslOnExit != null) {
final FlutterView flutterView = (await _vmService.getFlutterViews()).first;
final Map<String, Object> result = await (_vmService.getSkSLs(
final Map<String, Object?>? result = await _vmService.getSkSLs(
viewId: flutterView.id
) as FutureOr<Map<String, Object>>);
);
await sharedSkSlWriter(_device!, result, outputFile: writeSkslOnExit, logger: _logger);
}
// If the application package is available, stop and uninstall.
......
......@@ -934,7 +934,7 @@ abstract class ResidentHandlers {
viewId: views.first.id,
);
final Device device = flutterDevice.device!;
return sharedSkSlWriter(device, data!);
return sharedSkSlWriter(device, data);
}
/// Take a screenshot on the provided [device].
......
......@@ -13,12 +13,12 @@ import 'convert.dart';
import 'device.dart';
import 'globals.dart' as globals;
Future<String?> sharedSkSlWriter(Device device, Map<String, Object?> data, {
Future<String?> sharedSkSlWriter(Device device, Map<String, Object?>? data, {
File? outputFile,
Logger? logger,
}) async {
logger ??= globals.logger;
if (data.isEmpty) {
if (data == null || data.isEmpty) {
logger.printStatus(
'No data was received. To ensure SkSL data can be generated use a '
'physical device then:\n'
......
......@@ -56,7 +56,7 @@ class TestGoldenComparator {
/// to reduce the overhead of starting `flutter_tester`.
Future<TestGoldenComparatorProcess?> _processForTestFile(Uri testUri) async {
if (testUri == _previousTestUri) {
return _previousComparator;
return _previousComparator!;
}
final String bootstrap = TestGoldenComparatorProcess.generateBootstrap(_fileSystem.file(testUri), testUri, logger: _logger);
......@@ -68,7 +68,7 @@ class TestGoldenComparator {
_previousComparator = TestGoldenComparatorProcess(process, logger: _logger);
_previousTestUri = testUri;
return _previousComparator;
return _previousComparator!;
}
Future<Process?> _startProcess(String testBootstrap) async {
......@@ -100,7 +100,11 @@ class TestGoldenComparator {
Future<String?> compareGoldens(Uri testUri, Uint8List bytes, Uri goldenKey, bool? updateGoldens) async {
final File imageFile = await (await tempDir.createTemp('image')).childFile('image').writeAsBytes(bytes);
final TestGoldenComparatorProcess process = await (_processForTestFile(testUri) as FutureOr<TestGoldenComparatorProcess>);
final TestGoldenComparatorProcess? process = await _processForTestFile(testUri);
if (process == null) {
return 'process was null';
}
process.sendCommand(imageFile, goldenKey, updateGoldens);
final Map<String, dynamic> result = await process.getResponse();
......
......@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/base/dds.dart';
import 'package:flutter_tools/src/base/io.dart' as io;
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/build_info.dart';
......@@ -19,7 +18,6 @@ import 'package:flutter_tools/src/drive/drive_service.dart';
import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:flutter_tools/src/vmservice.dart';
import 'package:meta/meta.dart';
import 'package:package_config/package_config_types.dart';
import 'package:test/fake.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
......@@ -425,10 +423,10 @@ void main() {
}
FlutterDriverService setUpDriverService({
Logger logger,
ProcessManager processManager,
FlutterVmService vmService,
DevtoolsLauncher devtoolsLauncher,
Logger? logger,
ProcessManager? processManager,
FlutterVmService? vmService,
DevtoolsLauncher? devtoolsLauncher,
}) {
logger ??= BufferLogger.test();
return FlutterDriverService(
......@@ -441,14 +439,14 @@ FlutterDriverService setUpDriverService({
dartSdkPath: 'dart',
devtoolsLauncher: devtoolsLauncher ?? FakeDevtoolsLauncher(),
vmServiceConnector: (Uri httpUri, {
ReloadSources reloadSources,
Restart restart,
CompileExpression compileExpression,
GetSkSLMethod getSkSLMethod,
PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
Object compression,
Device device,
@required Logger logger,
ReloadSources? reloadSources,
Restart? restart,
CompileExpression? compileExpression,
GetSkSLMethod? getSkSLMethod,
PrintStructuredErrorLogMethod? printStructuredErrorLogMethod,
io.CompressionOptions compression = io.CompressionOptions.compressionDefault,
Device? device,
required Logger logger,
}) async {
assert(logger != null);
if (httpUri.scheme != 'http') {
......@@ -457,7 +455,7 @@ FlutterDriverService setUpDriverService({
if (httpUri.path.endsWith('/ws')) {
fail('Expected HTTP uri to not contain `/ws`, found $httpUri');
}
return vmService;
return vmService!;
}
);
}
......@@ -470,8 +468,8 @@ class FakeApplicationPackageFactory extends Fake implements ApplicationPackageFa
@override
Future<ApplicationPackage> getPackageForPlatform(
TargetPlatform platform, {
BuildInfo buildInfo,
File applicationBinary,
BuildInfo? buildInfo,
File? applicationBinary,
}) async => applicationPackage;
}
......@@ -505,21 +503,21 @@ class FakeDevice extends Fake implements Device {
@override
Future<DeviceLogReader> getLogReader({
covariant ApplicationPackage app,
covariant ApplicationPackage? app,
bool includePastLogs = false,
}) async => NoOpDeviceLogReader('test');
@override
Future<LaunchResult> startApp(
covariant ApplicationPackage package, {
String mainPath,
String route,
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
String? mainPath,
String? route,
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object?>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String userIdentifier,
}) async {
String? userIdentifier,
}) async {
if (failOnce) {
failOnce = false;
return LaunchResult.failed();
......@@ -528,13 +526,13 @@ class FakeDevice extends Fake implements Device {
}
@override
Future<bool> stopApp(covariant ApplicationPackage app, {String userIdentifier}) async {
Future<bool> stopApp(covariant ApplicationPackage app, {String? userIdentifier}) async {
didStopApp = true;
return true;
}
@override
Future<bool> uninstallApp(covariant ApplicationPackage app, {String userIdentifier}) async {
Future<bool> uninstallApp(covariant ApplicationPackage app, {String? userIdentifier}) async {
didUninstallApp = true;
return true;
}
......@@ -555,10 +553,10 @@ class FakeDartDevelopmentService extends Fake implements DartDevelopmentService
@override
Future<void> startDartDevelopmentService(
Uri observatoryUri, {
@required Logger logger,
int hostPort,
bool ipv6,
bool disableServiceAuthCodes,
required Logger logger,
int? hostPort,
bool? ipv6,
bool? disableServiceAuthCodes,
bool cacheStartupProfile = false,
}) async {
started = true;
......@@ -575,7 +573,7 @@ class FakeDevtoolsLauncher extends Fake implements DevtoolsLauncher {
final Completer<void> _processStarted = Completer<void>();
@override
Future<void> launch(Uri vmServiceUri, {List<String> additionalArguments}) {
Future<void> launch(Uri vmServiceUri, {List<String>? additionalArguments}) {
_processStarted.complete();
return Completer<void>().future;
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
......@@ -28,7 +26,7 @@ final Uint8List imageBytes = Uint8List.fromList(<int>[1, 2, 3, 4, 5]);
void main() {
group('Test that TestGoldenComparator', () {
FakeProcessManager processManager;
late FakeProcessManager processManager;
setUp(() {
processManager = FakeProcessManager.empty();
......@@ -63,7 +61,7 @@ void main() {
webRenderer: WebRendererMode.html,
);
final String result = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
final String? result = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
expect(result, null);
});
......@@ -92,7 +90,7 @@ void main() {
webRenderer: WebRendererMode.canvaskit,
);
final String result = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
final String? result = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
expect(result, 'some message');
});
......@@ -125,10 +123,10 @@ void main() {
webRenderer: WebRendererMode.html,
);
final String result1 = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
final String? result1 = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
expect(result1, 'some message');
final String result2 = await comparator.compareGoldens(testUri, imageBytes, goldenKey2, false);
final String? result2 = await comparator.compareGoldens(testUri, imageBytes, goldenKey2, false);
expect(result2, 'some other message');
});
......@@ -170,10 +168,10 @@ void main() {
webRenderer: WebRendererMode.canvaskit,
);
final String result1 = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
final String? result1 = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
expect(result1, 'some message');
final String result2 = await comparator.compareGoldens(testUri2, imageBytes, goldenKey2, false);
final String? result2 = await comparator.compareGoldens(testUri2, imageBytes, goldenKey2, false);
expect(result2, 'some other message');
});
......@@ -205,7 +203,7 @@ void main() {
webRenderer: WebRendererMode.html,
);
final String result = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
final String? result = await comparator.compareGoldens(testUri, imageBytes, goldenKey, false);
expect(result, null);
await comparator.close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment