Ignore dead_code hints for weak-only null checks. (#63007)

* Ignore dead_code hints for weak-only null checks.

When https://github.com/dart-lang/sdk/issues/41985 is fixed, the
analyzer will begin detecting dead code due to "unnecessary" null
checks.  Since we want to retain null checks in Flutter even when they
appear unnecessary (in order to preserve runtime behavior in weak
mode), we need to suppress these dead code hints.

* Add comments explaining why we're ignoring dead_code hints
This commit is contained in:
Paul Berry
2020-08-11 06:18:39 -07:00
committed by GitHub
parent d7883e3fb0
commit a4254c788f
2 changed files with 5 additions and 2 deletions

View File

@@ -66,8 +66,11 @@ abstract class AssetBundle {
/// implementation.)
Future<String> loadString(String key, { bool cache = true }) async {
final ByteData data = await load(key);
// Note: data has a non-nullable type, but might be null when running with
// weak checking, so we need to null check it anyway (and ignore the warning
// that the null-handling logic is dead code).
if (data == null)
throw FlutterError('Unable to load asset: $key');
throw FlutterError('Unable to load asset: $key'); // ignore: dead_code
if (data.lengthInBytes < 10 * 1024) {
// 10KB takes about 3ms to parse on a Pixel 2 XL.
// See: https://github.com/dart-lang/sdk/issues/31954

View File

@@ -88,7 +88,7 @@ class BasicMessageChannel<T> {
///
/// This is intended for testing. Messages intercepted in this manner are not
/// sent to platform plugins.
void setMockMessageHandler(Future<T> Function(T message) handler) {
void setMockMessageHandler(Future<T> Function(T message)? handler) {
if (handler == null) {
binaryMessenger.setMockMessageHandler(name, null);
} else {