Skip to content

Commit 2884788

Browse files
stereotype441mingwandroid
authored andcommitted
Ignore dead_code hints for weak-only null checks. (flutter#63007)
* Ignore dead_code hints for weak-only null checks. When dart-lang/sdk#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
1 parent 820be14 commit 2884788

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/flutter/lib/src/services/asset_bundle.dart

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

packages/flutter/lib/src/services/platform_channel.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class BasicMessageChannel<T> {
8888
///
8989
/// This is intended for testing. Messages intercepted in this manner are not
9090
/// sent to platform plugins.
91-
void setMockMessageHandler(Future<T> Function(T message) handler) {
91+
void setMockMessageHandler(Future<T> Function(T message)? handler) {
9292
if (handler == null) {
9393
binaryMessenger.setMockMessageHandler(name, null);
9494
} else {

0 commit comments

Comments
 (0)