From 9ec1601c46de9a05ae9ab16e0447fcda64e9e493 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 17 Dec 2020 11:37:34 -0800 Subject: [PATCH] Fix flutter in preparation for implementing Dart's "Infer non-nullability from local boolean variables" (#72494) When https://github.com/dart-lang/language/issues/1274 (Infer non-nullability from local boolean variables) is implemented, flow analysis will detect that code like this no longer needs to perform a null check: final bool contextIsValid = focus != null && focus.context != null; ... if (contextIsValid) { ... focus! ... // Null check unnecessary } To avoid a build failure due to the unnecessary null check, we need to temporarily write it in a way that we can ignore it. Once the feature is complete and rolled into flutter, I'll remove the null check entirely. --- .../flutter/lib/src/painting/image_provider.dart | 2 -- packages/flutter/lib/src/widgets/scrollable.dart | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/painting/image_provider.dart b/packages/flutter/lib/src/painting/image_provider.dart index 8ec67895a4..2a06f71e92 100644 --- a/packages/flutter/lib/src/painting/image_provider.dart +++ b/packages/flutter/lib/src/painting/image_provider.dart @@ -118,8 +118,6 @@ class ImageConfiguration { result.write('ImageConfiguration('); bool hasArguments = false; if (bundle != null) { - if (hasArguments) - result.write(', '); result.write('bundle: $bundle'); hasArguments = true; } diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index d1af1b26b8..a42767acc7 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -983,7 +983,17 @@ class ScrollAction extends Action { final bool contextIsValid = focus != null && focus.context != null; if (contextIsValid) { // Check for primary scrollable within the current context - if (Scrollable.of(focus!.context!) != null) + // After https://github.com/dart-lang/language/issues/1274 is implemented, + // `focus` will be promoted to non-nullable so we won't need to null check + // it (and it will cause a build failure to try to do so). Until then, we + // need to null check it in a way that won't cause a build failure once + // the feature is implemented. We can do that using an explicit "if" + // test. + // TODO(paulberry): remove this hack once the feature is implemented. + if (focus == null) { // ignore: dead_code + throw 'This throw is unreachable'; + } + if (Scrollable.of(focus.context!) != null) return true; // Check for fallback scrollable with context from PrimaryScrollController if (PrimaryScrollController.of(focus.context!) != null) {