Enable use_if_null_to_convert_nulls_to_bools lint (#98753)

This commit is contained in:
Tomasz Gucio
2022-02-22 23:39:20 +01:00
committed by GitHub
parent a7790d8e3a
commit e4351ff053
71 changed files with 179 additions and 166 deletions

View File

@@ -63,7 +63,7 @@ class AndroidWorkflow implements Workflow {
@override
bool get canLaunchDevices => appliesToHostPlatform && _androidSdk != null
&& _androidSdk?.adbPath != null
&& _androidSdk?.validateSdkWellFormed().isEmpty == true;
&& (_androidSdk?.validateSdkWellFormed().isEmpty ?? false);
@override
bool get canListEmulators => canListDevices && _androidSdk?.emulatorPath != null;

View File

@@ -232,7 +232,7 @@ class _Element extends _Entry {
_Attribute? firstAttribute(String name) {
for (final _Attribute child in children.whereType<_Attribute>()) {
if (child.key?.startsWith(name) == true) {
if (child.key?.startsWith(name) ?? false) {
return child;
}
}
@@ -241,7 +241,7 @@ class _Element extends _Entry {
_Element? firstElement(String name) {
for (final _Element child in children.whereType<_Element>()) {
if (child.name?.startsWith(name) == true) {
if (child.name?.startsWith(name) ?? false) {
return child;
}
}
@@ -249,7 +249,7 @@ class _Element extends _Entry {
}
Iterable<_Element> allElements(String name) {
return children.whereType<_Element>().where((_Element e) => e.name?.startsWith(name) == true);
return children.whereType<_Element>().where((_Element e) => e.name?.startsWith(name) ?? false);
}
}
@@ -332,7 +332,7 @@ class ApkManifestData {
final _Attribute? enabled = activity.firstAttribute('android:enabled');
final Iterable<_Element> intentFilters = activity.allElements('intent-filter');
final bool isEnabledByDefault = enabled == null;
final bool isExplicitlyEnabled = enabled != null && enabled.value?.contains('0xffffffff') == true;
final bool isExplicitlyEnabled = enabled != null && (enabled.value?.contains('0xffffffff') ?? false);
if (!(isEnabledByDefault || isExplicitlyEnabled)) {
continue;
}

View File

@@ -39,7 +39,7 @@ class DartDevelopmentService {
}) async {
final Uri ddsUri = Uri(
scheme: 'http',
host: (ipv6 == true ? io.InternetAddress.loopbackIPv6 : io.InternetAddress.loopbackIPv4).host,
host: ((ipv6 ?? false) ? io.InternetAddress.loopbackIPv6 : io.InternetAddress.loopbackIPv4).host,
port: hostPort ?? 0,
);
logger.printTrace(
@@ -51,7 +51,7 @@ class DartDevelopmentService {
observatoryUri,
serviceUri: ddsUri,
enableAuthCodes: disableServiceAuthCodes != true,
ipv6: ipv6 == true,
ipv6: ipv6 ?? false,
);
unawaited(_ddsInstance?.done.whenComplete(() {
if (!_completer.isCompleted) {

View File

@@ -447,7 +447,7 @@ class StdoutLogger extends Logger {
shouldWrap: wrap ?? _outputPreferences.wrapText,
columnWidth: _outputPreferences.wrapColumn,
);
if (emphasis == true) {
if (emphasis ?? false) {
message = terminal.bolden(message);
}
message = terminal.color(message, color ?? TerminalColor.red);
@@ -475,7 +475,7 @@ class StdoutLogger extends Logger {
shouldWrap: wrap ?? _outputPreferences.wrapText,
columnWidth: _outputPreferences.wrapColumn,
);
if (emphasis == true) {
if (emphasis ?? false) {
message = terminal.bolden(message);
}
message = terminal.color(message, color ?? TerminalColor.cyan);
@@ -500,13 +500,13 @@ class StdoutLogger extends Logger {
shouldWrap: wrap ?? _outputPreferences.wrapText,
columnWidth: _outputPreferences.wrapColumn,
);
if (emphasis == true) {
if (emphasis ?? false) {
message = terminal.bolden(message);
}
if (color != null) {
message = terminal.color(message, color);
}
if (newline != false) {
if (newline ?? true) {
message = '$message\n';
}
writeToStdOut(message);
@@ -812,7 +812,7 @@ class BufferLogger extends Logger {
int? hangingIndent,
bool? wrap,
}) {
if (newline != false) {
if (newline ?? true) {
_status.writeln(wrapText(message,
indent: indent,
hangingIndent: hangingIndent,

View File

@@ -458,7 +458,7 @@ class _DefaultProcessUtils implements ProcessUtils {
}
if (mappedLine != null) {
final String message = '$prefix$mappedLine';
if (stdoutErrorMatcher?.hasMatch(mappedLine) == true) {
if (stdoutErrorMatcher?.hasMatch(mappedLine) ?? false) {
_logger.printError(message, wrap: false);
} else if (trace) {
_logger.printTrace(message);

View File

@@ -121,7 +121,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
Future<void> validateCommand() async {
final String? exportOptions = exportOptionsPlist;
if (exportOptions != null) {
if (argResults?.wasParsed('export-method') == true) {
if (argResults?.wasParsed('export-method') ?? false) {
throwToolExit(
'"--export-options-plist" is not compatible with "--export-method". Either use "--export-options-plist" and '
'a plist describing how the IPA should be exported by Xcode, or use "--export-method" to create a new plist.\n'

View File

@@ -116,7 +116,7 @@ class ConfigCommand extends FlutterCommand {
return FlutterCommandResult.success();
}
if (argResults?.wasParsed('analytics') == true) {
if (argResults?.wasParsed('analytics') ?? false) {
final bool value = boolArg('analytics');
// The tool sends the analytics event *before* toggling the flag
// intentionally to be sure that opt-out events are sent correctly.
@@ -131,19 +131,19 @@ class ConfigCommand extends FlutterCommand {
globals.printStatus('Analytics reporting ${value ? 'enabled' : 'disabled'}.');
}
if (argResults?.wasParsed('android-sdk') == true) {
if (argResults?.wasParsed('android-sdk') ?? false) {
_updateConfig('android-sdk', stringArg('android-sdk')!);
}
if (argResults?.wasParsed('android-studio-dir') == true) {
if (argResults?.wasParsed('android-studio-dir') ?? false) {
_updateConfig('android-studio-dir', stringArg('android-studio-dir')!);
}
if (argResults?.wasParsed('clear-ios-signing-cert') == true) {
if (argResults?.wasParsed('clear-ios-signing-cert') ?? false) {
_updateConfig('ios-signing-cert', '');
}
if (argResults?.wasParsed('build-dir') == true) {
if (argResults?.wasParsed('build-dir') ?? false) {
final String buildDir = stringArg('build-dir')!;
if (globals.fs.path.isAbsolute(buildDir)) {
throwToolExit('build-dir should be a relative path');
@@ -156,7 +156,7 @@ class ConfigCommand extends FlutterCommand {
if (configSetting == null) {
continue;
}
if (argResults?.wasParsed(configSetting) == true) {
if (argResults?.wasParsed(configSetting) ?? false) {
final bool keyValue = boolArg(configSetting);
globals.config.setValue(configSetting, keyValue);
globals.printStatus('Setting "$configSetting" value to "$keyValue".');

View File

@@ -56,7 +56,7 @@ class DebugAdapterCommand extends FlutterCommand {
globals.stdio.stdout.nonBlocking,
fileSystem: globals.fs,
platform: globals.platform,
ipv6: ipv6 == true,
ipv6: ipv6 ?? false,
enableDds: enableDds,
test: boolArg('test'),
);

View File

@@ -34,7 +34,7 @@ class DoctorCommand extends FlutterCommand {
@override
Future<FlutterCommandResult> runCommand() async {
globals.flutterVersion.fetchTagsAndUpdate();
if (argResults?.wasParsed('check-for-remote-artifacts') == true) {
if (argResults?.wasParsed('check-for-remote-artifacts') ?? false) {
final String engineRevision = stringArg('check-for-remote-artifacts')!;
if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) {
final bool success = await globals.doctor?.checkRemoteArtifacts(engineRevision) ?? false;

View File

@@ -100,7 +100,7 @@ class ScreenshotCommand extends FlutterCommand {
@override
Future<FlutterCommandResult> runCommand() async {
File? outputFile;
if (argResults?.wasParsed(_kOut) == true) {
if (argResults?.wasParsed(_kOut) ?? false) {
outputFile = globals.fs.file(stringArg(_kOut));
}

View File

@@ -71,7 +71,7 @@ class SymbolizeCommand extends FlutterCommand {
if (!_fileSystem.isFileSync(stringArg('debug-info')!)) {
throwToolExit('${stringArg('debug-info')} does not exist.');
}
if (argResults?.wasParsed('input') == true && !_fileSystem.isFileSync(stringArg('input')!)) {
if ((argResults?.wasParsed('input') ?? false) && !_fileSystem.isFileSync(stringArg('input')!)) {
throwToolExit('${stringArg('input')} does not exist.');
}
return super.validateCommand();
@@ -83,7 +83,7 @@ class SymbolizeCommand extends FlutterCommand {
IOSink output;
// Configure output to either specified file or stdout.
if (argResults?.wasParsed('output') == true) {
if (argResults?.wasParsed('output') ?? false) {
final File outputFile = _fileSystem.file(stringArg('output'));
if (!outputFile.parent.existsSync()) {
outputFile.parent.createSync(recursive: true);
@@ -99,7 +99,7 @@ class SymbolizeCommand extends FlutterCommand {
}
// Configure input from either specified file or stdin.
if (argResults?.wasParsed('input') == true) {
if (argResults?.wasParsed('input') ?? false) {
input = _fileSystem.file(stringArg('input')).openRead();
} else {
input = _stdio.stdin;

View File

@@ -95,7 +95,7 @@ class DevFSFileContent extends DevFSContent {
if (fileStat.type == FileSystemEntityType.notFound) {
_fileStat = null;
_linkTarget = null;
} else if (devFSConfig?.cacheSymlinks == true) {
} else if (devFSConfig?.cacheSymlinks ?? false) {
_linkTarget = linkTarget;
}
}

View File

@@ -130,7 +130,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
NoIdeValidator(),
if (proxyValidator.shouldShow)
proxyValidator,
if (globals.deviceManager?.canListAnything == true)
if (globals.deviceManager?.canListAnything ?? false)
DeviceValidator(
deviceManager: globals.deviceManager,
userMessages: globals.userMessages,
@@ -153,11 +153,11 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
_workflows!.add(globals.iosWorkflow!);
}
if (androidWorkflow?.appliesToHostPlatform == true) {
if (androidWorkflow?.appliesToHostPlatform ?? false) {
_workflows!.add(androidWorkflow!);
}
if (fuchsiaWorkflow?.appliesToHostPlatform == true) {
if (fuchsiaWorkflow?.appliesToHostPlatform ?? false) {
_workflows!.add(fuchsiaWorkflow!);
}
@@ -169,7 +169,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
_workflows!.add(macOSWorkflow);
}
if (windowsWorkflow?.appliesToHostPlatform == true) {
if (windowsWorkflow?.appliesToHostPlatform ?? false) {
_workflows!.add(windowsWorkflow!);
}

View File

@@ -273,7 +273,7 @@ class FlutterManifest {
Map<String, Object?>? get supportedPlatforms {
if (isPlugin) {
final YamlMap? plugin = _flutterDescriptor['plugin'] as YamlMap?;
if (plugin?.containsKey('platforms') == true) {
if (plugin?.containsKey('platforms') ?? false) {
final YamlMap? platformsMap = plugin!['platforms'] as YamlMap?;
return platformsMap?.value.cast<String, Object?>();
}

View File

@@ -393,8 +393,8 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
final List<String> pluginsUsingV1 = <String>[];
for (final Map<String, Object?> plugin in androidPlugins) {
final bool supportsEmbeddingV1 = (plugin['supportsEmbeddingV1'] as bool?) == true;
final bool supportsEmbeddingV2 = (plugin['supportsEmbeddingV2'] as bool?) == true;
final bool supportsEmbeddingV1 = (plugin['supportsEmbeddingV1'] as bool?) ?? false;
final bool supportsEmbeddingV2 = (plugin['supportsEmbeddingV2'] as bool?) ?? false;
if (supportsEmbeddingV1 && !supportsEmbeddingV2) {
templateContext['needsShim'] = true;
if (plugin['name'] != null) {
@@ -431,8 +431,8 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
'Take a look at the docs for migrating an app: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects'
);
for (final Map<String, Object?> plugin in androidPlugins) {
final bool supportsEmbeddingV1 = (plugin['supportsEmbeddingV1'] as bool?) == true;
final bool supportsEmbeddingV2 = (plugin['supportsEmbeddingV2'] as bool?) == true;
final bool supportsEmbeddingV1 = (plugin['supportsEmbeddingV1'] as bool?) ?? false;
final bool supportsEmbeddingV2 = (plugin['supportsEmbeddingV2'] as bool?) ?? false;
if (!supportsEmbeddingV1 && supportsEmbeddingV2) {
throwToolExit(
'The plugin `${plugin['name']}` requires your app to be migrated to '

View File

@@ -723,7 +723,7 @@ class FuchsiaDevice extends Device {
continue;
}
final int? port = vmService.httpAddress?.port;
if (port != null && uiIsolate.name?.contains(isolateName) == true) {
if (port != null && (uiIsolate.name?.contains(isolateName) ?? false)) {
return port;
}
}
@@ -821,7 +821,7 @@ class FuchsiaIsolateDiscoveryProtocol {
continue;
}
final int? port = service?.httpAddress?.port;
if (port != null && uiIsolate.name?.contains(_isolateName) == true) {
if (port != null && (uiIsolate.name?.contains(_isolateName) ?? false)) {
_foundUri.complete(_device.ipv6
? Uri.parse('http://[$_ipv6Loopback]:$port/')
: Uri.parse('http://$_ipv4Loopback:$port/'));

View File

@@ -230,7 +230,7 @@ class FuchsiaPackageServer {
if (_process == null) {
return false;
}
return (await globals.fuchsiaSdk?.fuchsiaPM.publish(_repo, package.path)) == true;
return (await globals.fuchsiaSdk?.fuchsiaPM.publish(_repo, package.path)) ?? false;
}
@override

View File

@@ -14,7 +14,7 @@ class IOSEmulators extends EmulatorDiscovery {
bool get supportsPlatform => globals.platform.isMacOS;
@override
bool get canListAnything => globals.iosWorkflow?.canListEmulators == true;
bool get canListAnything => globals.iosWorkflow?.canListEmulators ?? false;
@override
Future<List<Emulator>> get emulators async => getEmulators();

View File

@@ -561,9 +561,9 @@ return result.exitCode != 0 &&
Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsage, Logger logger) async {
final XcodeBuildExecution? xcodeBuildExecution = result.xcodeBuildExecution;
if (xcodeBuildExecution != null &&
xcodeBuildExecution.environmentType == EnvironmentType.physical &&
result.stdout?.toUpperCase().contains('BITCODE') == true) {
if (xcodeBuildExecution != null
&& xcodeBuildExecution.environmentType == EnvironmentType.physical
&& (result.stdout?.toUpperCase().contains('BITCODE') ?? false)) {
BuildEvent('xcode-bitcode-failure',
type: 'ios',
command: xcodeBuildExecution.buildCommands.toString(),
@@ -575,9 +575,9 @@ Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsa
// Building for iOS Simulator, but the linked and embedded framework 'App.framework' was built for iOS.
// or
// Building for iOS, but the linked and embedded framework 'App.framework' was built for iOS Simulator.
if (result.stdout?.contains('Building for iOS') == true
&& result.stdout?.contains('but the linked and embedded framework') == true
&& result.stdout?.contains('was built for iOS') == true) {
if ((result.stdout?.contains('Building for iOS') ?? false)
&& (result.stdout?.contains('but the linked and embedded framework') ?? false)
&& (result.stdout?.contains('was built for iOS') ?? false)) {
logger.printError('');
logger.printError('Your Xcode project requires migration. See https://flutter.dev/docs/development/ios-project-migration for details.');
logger.printError('');
@@ -585,11 +585,11 @@ Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsa
logger.printError(' flutter clean');
return;
}
if (xcodeBuildExecution != null &&
xcodeBuildExecution.environmentType == EnvironmentType.physical &&
result.stdout?.contains('BCEROR') == true &&
if (xcodeBuildExecution != null
&& xcodeBuildExecution.environmentType == EnvironmentType.physical
&& (result.stdout?.contains('BCEROR') ?? false)
// May need updating if Xcode changes its outputs.
result.stdout?.contains("Xcode couldn't find a provisioning profile matching") == true) {
&& (result.stdout?.contains("Xcode couldn't find a provisioning profile matching") ?? false)) {
logger.printError(noProvisioningProfileInstruction, emphasis: true);
return;
}
@@ -603,9 +603,9 @@ Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsa
logger.printError(noDevelopmentTeamInstruction, emphasis: true);
return;
}
if (xcodeBuildExecution != null &&
xcodeBuildExecution.environmentType == EnvironmentType.physical &&
xcodeBuildExecution.buildSettings['PRODUCT_BUNDLE_IDENTIFIER']?.contains('com.example') == true) {
if (xcodeBuildExecution != null
&& xcodeBuildExecution.environmentType == EnvironmentType.physical
&& (xcodeBuildExecution.buildSettings['PRODUCT_BUNDLE_IDENTIFIER']?.contains('com.example') ?? false)) {
logger.printError('');
logger.printError('It appears that your application still contains the default signing identifier.');
logger.printError("Try replacing 'com.example' with your signing id in Xcode:");

View File

@@ -45,7 +45,7 @@ Future<void> processPodsIfNeeded(
xcodeProject: xcodeProject,
buildMode: buildMode,
dependenciesChanged: !fingerprinter.doesFingerprintMatch(),
) == true;
) ?? false;
if (didPodInstall) {
fingerprinter.writeFingerprint();
}

View File

@@ -206,7 +206,7 @@ class XCDevice {
unawaited(stdoutSubscription.cancel());
unawaited(stderrSubscription.cancel());
}).whenComplete(() async {
if (_deviceIdentifierByEvent?.hasListener == true) {
if (_deviceIdentifierByEvent?.hasListener ?? false) {
// Tell listeners the process died.
await _deviceIdentifierByEvent?.close();
}

View File

@@ -62,7 +62,7 @@ class CmakeCustomCommandMigration extends ProjectMigrator {
// Manually-specified variables were not used by the project:
// FLUTTER_TARGET_PLATFORM
// ------------------------------
if (addCustomCommandOriginal?.contains('linux-x64') == true) {
if (addCustomCommandOriginal?.contains('linux-x64') ?? false) {
newProjectContents = newProjectContents.replaceAll('linux-x64', r'${FLUTTER_TARGET_PLATFORM}');
}
}

View File

@@ -474,7 +474,7 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
bool? ffiPlugin,
this.defaultPackage,
}) : ffiPlugin = ffiPlugin ?? false,
assert(pluginClass != null || dartPluginClass != null || ffiPlugin == true || defaultPackage != null);
assert(pluginClass != null || dartPluginClass != null || (ffiPlugin ?? false) || defaultPackage != null);
factory LinuxPlugin.fromYaml(String name, YamlMap yaml) {
assert(validate(yaml));

View File

@@ -164,7 +164,7 @@ class PreviewDevice extends Device {
@override
Future<bool> stopApp(covariant ApplicationPackage app, {String? userIdentifier}) async {
return _process?.kill() == true;
return _process?.kill() ?? false;
}
@override

View File

@@ -290,7 +290,7 @@ abstract class FlutterCommand extends Command<void> {
}
String get targetFile {
if (argResults?.wasParsed('target') == true) {
if (argResults?.wasParsed('target') ?? false) {
return stringArg('target')!;
}
final List<String>? rest = argResults?.rest;
@@ -422,8 +422,8 @@ abstract class FlutterCommand extends Command<void> {
late final bool enableDds = () {
bool ddsEnabled = false;
if (argResults?.wasParsed('disable-dds') == true) {
if (argResults?.wasParsed('dds') == true) {
if (argResults?.wasParsed('disable-dds') ?? false) {
if (argResults?.wasParsed('dds') ?? false) {
throwToolExit(
'The "--[no-]dds" and "--[no-]disable-dds" arguments are mutually exclusive. Only specify "--[no-]dds".');
}
@@ -444,8 +444,8 @@ abstract class FlutterCommand extends Command<void> {
return ddsEnabled;
}();
bool get _hostVmServicePortProvided => argResults?.wasParsed('observatory-port') == true ||
argResults?.wasParsed('host-vmservice-port') == true;
bool get _hostVmServicePortProvided => (argResults?.wasParsed('observatory-port') ?? false)
|| (argResults?.wasParsed('host-vmservice-port') ?? false);
int _tryParseHostVmservicePort() {
final String? observatoryPort = stringArg('observatory-port');
@@ -464,7 +464,7 @@ abstract class FlutterCommand extends Command<void> {
if (argResults?.wasParsed('dds-port') != true && _hostVmServicePortProvided) {
// If an explicit DDS port is _not_ provided, use the host-vmservice-port for DDS.
return _tryParseHostVmservicePort();
} else if (argResults?.wasParsed('dds-port') == true) {
} else if (argResults?.wasParsed('dds-port') ?? false) {
// If an explicit DDS port is provided, use dds-port for DDS.
return int.tryParse(stringArg('dds-port')!) ?? 0;
}
@@ -473,7 +473,7 @@ abstract class FlutterCommand extends Command<void> {
}
Uri? get devToolsServerAddress {
if (argResults?.wasParsed(kDevToolsServerAddress) == true) {
if (argResults?.wasParsed(kDevToolsServerAddress) ?? false) {
final Uri? uri = Uri.tryParse(stringArg(kDevToolsServerAddress)!);
if (uri != null && uri.host.isNotEmpty && uri.port != 0) {
return uri;
@@ -493,8 +493,8 @@ abstract class FlutterCommand extends Command<void> {
if (!_usesPortOption || !_hostVmServicePortProvided) {
return null;
}
if (argResults?.wasParsed('observatory-port') == true &&
argResults?.wasParsed('host-vmservice-port') == true) {
if ((argResults?.wasParsed('observatory-port') ?? false)
&& (argResults?.wasParsed('host-vmservice-port') ?? false)) {
throwToolExit('Only one of "--observatory-port" and '
'"--host-vmservice-port" may be specified.');
}
@@ -612,8 +612,8 @@ abstract class FlutterCommand extends Command<void> {
bool get reportNullSafety => false;
late final Duration? deviceDiscoveryTimeout = () {
if (argResults?.options.contains(FlutterOptions.kDeviceTimeout) == true
&& argResults?.wasParsed(FlutterOptions.kDeviceTimeout) == true) {
if ((argResults?.options.contains(FlutterOptions.kDeviceTimeout) ?? false)
&& (argResults?.wasParsed(FlutterOptions.kDeviceTimeout) ?? false)) {
final int? timeoutSeconds = int.tryParse(stringArg(FlutterOptions.kDeviceTimeout)!);
if (timeoutSeconds == null) {
throwToolExit( 'Could not parse "--${FlutterOptions.kDeviceTimeout}" argument. It must be an integer.');
@@ -1000,7 +1000,7 @@ abstract class FlutterCommand extends Command<void> {
// Explicitly check for `true` and `false` so that `null` results in not
// passing a flag. Examine the entrypoint file to determine if it
// is opted in or out.
final bool wasNullSafetyFlagParsed = argResults?.wasParsed(FlutterOptions.kNullSafety) == true;
final bool wasNullSafetyFlagParsed = argResults?.wasParsed(FlutterOptions.kNullSafety) ?? false;
if (!wasNullSafetyFlagParsed && (argParser.options.containsKey('target') || forcedTargetFile != null)) {
final File entrypointFile = forcedTargetFile ?? globals.fs.file(targetFile);
final LanguageVersion languageVersion = determineLanguageVersion(

View File

@@ -205,12 +205,12 @@ class FlutterCommandRunner extends CommandRunner<void> {
wrapColumn: wrapColumn,
);
if ((topLevelResults['show-test-device'] as bool?) == true ||
topLevelResults['device-id'] == FlutterTesterDevices.kTesterDeviceId) {
if (((topLevelResults['show-test-device'] as bool?) ?? false)
|| topLevelResults['device-id'] == FlutterTesterDevices.kTesterDeviceId) {
FlutterTesterDevices.showFlutterTesterDevice = true;
}
if ((topLevelResults['show-web-server-device'] as bool?) == true ||
topLevelResults['device-id'] == WebServerDevice.kWebServerDeviceId) {
if (((topLevelResults['show-web-server-device'] as bool?) ?? false)
|| topLevelResults['device-id'] == WebServerDevice.kWebServerDeviceId) {
WebServerDevice.showWebServerDevice = true;
}
@@ -231,13 +231,13 @@ class FlutterCommandRunner extends CommandRunner<void> {
return MapEntry<Type, Generator>(type, () => value);
}),
body: () async {
globals.logger.quiet = (topLevelResults['quiet'] as bool?) == true;
globals.logger.quiet = (topLevelResults['quiet'] as bool?) ?? false;
if (globals.platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true') {
await globals.cache.lock();
}
if ((topLevelResults['suppress-analytics'] as bool?) == true) {
if ((topLevelResults['suppress-analytics'] as bool?) ?? false) {
globals.flutterUsage.suppressAnalytics = true;
}
@@ -258,7 +258,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
// See if the user specified a specific device.
globals.deviceManager?.specifiedDeviceId = topLevelResults['device-id'] as String?;
if ((topLevelResults['version'] as bool?) == true) {
if ((topLevelResults['version'] as bool?) ?? false) {
globals.flutterUsage.sendCommand('version');
globals.flutterVersion.fetchTagsAndUpdate();
String status;

View File

@@ -166,7 +166,7 @@ class Template {
throwToolExit('Failed to flutter create at ${destination.path}.');
}
int fileCount = 0;
final bool implementationTests = (context['implementationTests'] as bool?) == true;
final bool implementationTests = (context['implementationTests'] as bool?) ?? false;
/// Returns the resolved destination path corresponding to the specified
/// raw destination path, after performing language filtering and template
@@ -184,38 +184,38 @@ class Template {
relativeDestinationPath = relativeDestinationPath.replaceAll('$platform-$language.tmpl', platform);
}
final bool android = (context['android'] as bool?) == true;
final bool android = (context['android'] as bool?) ?? false;
if (relativeDestinationPath.contains('android') && !android) {
return null;
}
final bool ios = (context['ios'] as bool?) == true;
final bool ios = (context['ios'] as bool?) ?? false;
if (relativeDestinationPath.contains('ios') && !ios) {
return null;
}
// Only build a web project if explicitly asked.
final bool web = (context['web'] as bool?) == true;
final bool web = (context['web'] as bool?) ?? false;
if (relativeDestinationPath.contains('web') && !web) {
return null;
}
// Only build a Linux project if explicitly asked.
final bool linux = (context['linux'] as bool?) == true;
final bool linux = (context['linux'] as bool?) ?? false;
if (relativeDestinationPath.startsWith('linux.tmpl') && !linux) {
return null;
}
// Only build a macOS project if explicitly asked.
final bool macOS = (context['macos'] as bool?) == true;
final bool macOS = (context['macos'] as bool?) ?? false;
if (relativeDestinationPath.startsWith('macos.tmpl') && !macOS) {
return null;
}
// Only build a Windows project if explicitly asked.
final bool windows = (context['windows'] as bool?) == true;
final bool windows = (context['windows'] as bool?) ?? false;
if (relativeDestinationPath.startsWith('windows.tmpl') && !windows) {
return null;
}
// Only build a Windows UWP project if explicitly asked.
final bool windowsUwp = (context['winuwp'] as bool?) == true;
final bool windowsUwp = (context['winuwp'] as bool?) ?? false;
if (relativeDestinationPath.startsWith('winuwp.tmpl') && !windowsUwp) {
return null;
}

View File

@@ -866,7 +866,7 @@ class FlutterVmService {
final List<vm_service.IsolateRef> refs = await _getIsolateRefs();
for (final vm_service.IsolateRef ref in refs) {
final vm_service.Isolate? isolate = await getIsolateOrNull(ref.id!);
if (isolate != null && isolate.extensionRPCs?.contains(extensionName) == true) {
if (isolate != null && (isolate.extensionRPCs?.contains(extensionName) ?? false)) {
return ref;
}
}

View File

@@ -293,7 +293,7 @@ class VsCode {
final String jsonString = fileSystem.file(packageJsonPath).readAsStringSync();
try {
final Map<String, dynamic>? jsonObject = castStringKeyedMap(json.decode(jsonString));
if (jsonObject?.containsKey('version') == true) {
if (jsonObject?.containsKey('version') ?? false) {
return jsonObject!['version'] as String;
}
} on FormatException {

View File

@@ -230,7 +230,7 @@ class IosProject extends XcodeBasedProject {
// https://flutter.dev/docs/deployment/ios#review-xcode-project-settings
// The only source of truth for the name is Xcode's interpretation of the build settings.
String? productName;
if (globals.xcodeProjectInterpreter?.isInstalled == true) {
if (globals.xcodeProjectInterpreter?.isInstalled ?? false) {
final Map<String, String>? xcodeBuildSettings = await buildSettingsForBuildInfo(buildInfo);
if (xcodeBuildSettings != null) {
productName = xcodeBuildSettings['FULL_PRODUCT_NAME'];

View File

@@ -158,7 +158,7 @@ abstract class FlutterTestDriver {
_vmService!.streamListen('Debug'),
]);
if ((await _vmService!.getVM()).isolates?.isEmpty != false) {
if ((await _vmService!.getVM()).isolates?.isEmpty ?? true) {
await isolateStarted.future;
}
@@ -287,7 +287,7 @@ abstract class FlutterTestDriver {
return _vmService!.onDebugEvent
.where((Event event) {
return event.isolate?.id == isolateId
&& event.kind?.startsWith(kind) == true;
&& (event.kind?.startsWith(kind) ?? false);
}).first;
}
@@ -302,7 +302,7 @@ abstract class FlutterTestDriver {
// don't need to wait for the event.
final VmService vmService = _vmService!;
final Isolate isolate = await vmService.getIsolate(isolateId);
if (isolate.pauseEvent?.kind?.startsWith(kind) == true) {
if (isolate.pauseEvent?.kind?.startsWith(kind) ?? false) {
_debugPrint('Isolate was already at "$kind" (${isolate.pauseEvent!.kind}).');
event.ignore();
} else {
@@ -324,7 +324,7 @@ abstract class FlutterTestDriver {
Future<bool> isAtAsyncSuspension() async {
final Isolate isolate = await getFlutterIsolate();
return isolate.pauseEvent?.atAsyncSuspension == true;
return isolate.pauseEvent?.atAsyncSuspension ?? false;
}
Future<Isolate?> stepOverOrOverAsyncSuspension({ bool waitForNextPause = true }) async {