Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions script/tool/lib/src/update_dependency_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class UpdateDependencyCommand extends PackageLoopingCommand {
final String? version = getNullableStringArg(_versionFlag);
if (version == null) {
final PubVersionFinderResponse response = await _pubVersionFinder
.getPackageVersion(packageName: _targetPubPackage);
.getPackageVersion(packageName: _targetPubPackage!);
switch (response.result) {
case PubVersionFinderResult.success:
_targetVersion = response.versions.first.toString();
Expand Down Expand Up @@ -204,7 +204,7 @@ A version with a valid format (3 numbers separated by 2 periods) must be provide
@override
Future<PackageResult> runForPackage(RepositoryPackage package) async {
if (_targetPubPackage != null) {
return _runForPubDependency(package, _targetPubPackage);
return _runForPubDependency(package, _targetPubPackage!);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While using ! is valid here because of the null check on the previous line, a more idiomatic and safer approach in Dart is to assign the nullable field to a local variable. This allows Dart's flow analysis to promote the variable to a non-nullable type within an if block, avoiding the need for a null assertion.

Consider refactoring this block to:

    final String? targetPubPackage = _targetPubPackage;
    if (targetPubPackage != null) {
      return _runForPubDependency(package, targetPubPackage);
    }

}
if (_targetAndroidDependency != null) {
return _runForAndroidDependency(package);
Expand Down