dart-lang / pana

Package ANAlysis for Dart
https://pub.dev/packages/pana
BSD 3-Clause "New" or "Revised" License
204 stars 44 forks source link

why is google_maps_flutter_web not null-safe? #1136

Closed jonasfj closed 1 year ago

jonasfj commented 1 year ago

https://pub.dev/packages/google_maps_flutter_web/score

jonasfj commented 1 year ago

Is that a similar problem with: https://pub.dev/packages/supabase_flutter/score

Maybe, we should look through results from: https://pub.dev/packages?q=-is%3Anull-safe&sort=updated&page=1

isoos commented 1 year ago

The root cause seems to be that some Dart SDK libraries are not available on Flutter SDK, e.g. dart:web_gl in this case. package:google_maps_flutter_web depends on package:google_maps, and the later is able to import dart:web_gl. Because package:google_maps is a generic package, and it is analyzed with Dart SDK, pana is successful identifying it as null-safe. However, package:google_maps_flutter_web is analyzed with Flutter SDK, and in the transitive import path it ends up importing dart:web_gl, which is not available, therefore the analysis fails.

For package:supabase_flutter it is the same thing happening with package:hive and dart:indexed_db.

A quick fix could be to allow-list Dart SDK libraries that are missing from Flutter SDK, and if they are imported via a transitive dependency, we don't fail the analysis.

Another fix could be to restructure the current null-safety detection code. If I understand it correctly, we are iterating over Runtime.recognizedRuntimes and require for each that all public libraries have accessible and null-safe dependencies. https://github.com/dart-lang/pana/blob/master/lib/src/tag/tagger.dart#L388-L435

Instead, we could do the following changes:

/cc @jonasfj @sigurdm wdyt?