Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[device_info_platform_interface][device_info] nnbd #3144

Merged
merged 18 commits into from
Oct 16, 2020

Conversation

cyanglaz
Copy link
Contributor

Migrate to NNBD

@blasten
Copy link

blasten commented Oct 14, 2020

We would need to opt out the driver tests in the PR for device_info until integration_test and vm_service are migrated to null safety.

FYI @dnfield

@dnfield
Copy link
Contributor

dnfield commented Oct 14, 2020

@bkonyi what's the plan for null safe vm_service?

Comment on lines 101 to 105
'utsname.sysname:': data.utsname?.sysname,
'utsname.nodename:': data.utsname?.nodename,
'utsname.release:': data.utsname?.release,
'utsname.version:': data.utsname?.version,
'utsname.machine:': data.utsname?.machine,
Copy link

Choose a reason for hiding this comment

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

similar comment about nullability.

}) : supported32BitAbis = List<String>.unmodifiable(supported32BitAbis),
supported64BitAbis = List<String>.unmodifiable(supported64BitAbis),
supportedAbis = List<String>.unmodifiable(supportedAbis),
systemFeatures = List<String>.unmodifiable(systemFeatures);

/// Android operating system version values derived from `android.os.Build.VERSION`.
final AndroidBuildVersion version;
final AndroidBuildVersion? version;
Copy link

@blasten blasten Oct 14, 2020

Choose a reason for hiding this comment

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

It seems like only baseOS, previewSdkInt, and securityPatch should be nullable:

Copy link
Contributor Author

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

@blasten Updated per review comments, PTAL

Chris Yang added 2 commits October 15, 2020 10:59
@@ -19,14 +22,15 @@ flutter:
dependencies:
flutter:
sdk: flutter
device_info_platform_interface: ^1.0.0
device_info_platform_interface:
path: ../device_info_platform_interface
Copy link

Choose a reason for hiding this comment

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

We are going with git dependencies, but feel free to change it after this PR is merged.

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM

@cyanglaz cyanglaz merged commit f98493d into flutter:nnbd Oct 16, 2020
this.androidId,
List<String> systemFeatures,
}) : supported32BitAbis = List<String>.unmodifiable(supported32BitAbis),
required this.version,
Copy link
Contributor

Choose a reason for hiding this comment

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

We have forked this package internally and my migration followed a different path. I am not a fan of making all these fields required for two reasons:

  • Constructing the object (for tests) becomes painful. Consider an app test that only needs to set manufacturer. They now have to initialize all the other fields in their tests or use the obscure Map constructor.
  • Semantically, these fields are not required to exist. They can be empty. To reflect that, we are initializing them to empty string. As an app developer, I would much rather have a signal that a field is nullable rather than having it be an empty string which does not provide compile-time safety.

In my migration, I marked all these fields as nullable. However, this failed tests because gallery uses this code and assumes they are not nullable.

Copy link

Choose a reason for hiding this comment

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

Semantically, these fields are not required to exist. They can be empty. To reflect that, we are initializing them to empty string.

If it's referring to usage of Map, this is a limitation of the implementation.

When looking at this, we were trying to answer the question of what is a valid AndroidDeviceInfo based on the information available from the platform. If something changes in future versions of Android, then that is a breaking change to the API exposed to Dart.

In my opinion, if everything is nullable by default, then the API becomes some sort of "best-effort". "we think version is available, but we can't guarantee that".

This was the rationale behind it. That said, could you point to the cases where testing was painful?

Copy link
Contributor

Choose a reason for hiding this comment

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

we were trying to answer the question of what is a valid AndroidDeviceInfo based on the information available from the platform.

That means these fields are not supposed to be nullable. In that case, it would be far better to construct them via map values like so:

   someField: map[key]!,
   // rather than
   // someField: map[key] ?? '',

The code, today, reads like any one of these values can be non-existent and that's OK.

The test pain is a secondary reason. If these are truly non-nullable values, you can always expose a forTest constructor that effectively does what your map constructor is doing.

Copy link

Choose a reason for hiding this comment

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

someField: map[key]! makes sense to me. We should fix it. This is an area where I think Pigeon could help, but that is a different discussion 😃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants