Prepare packages for binding.instance becoming non-nullable (#546)

diff --git a/packages/animations/lib/src/open_container.dart b/packages/animations/lib/src/open_container.dart
index e2eb5a4..67ec13e 100644
--- a/packages/animations/lib/src/open_container.dart
+++ b/packages/animations/lib/src/open_container.dart
@@ -628,7 +628,7 @@
     if (hideableKey.currentState?.isVisible == false) {
       // This route may be disposed without dismissing its animation if it is
       // removed by the navigator.
-      SchedulerBinding.instance!
+      _ambiguate(SchedulerBinding.instance)!
           .addPostFrameCallback((Duration d) => _toggleHideable(hide: false));
     }
     super.dispose();
@@ -662,7 +662,7 @@
     }
 
     if (delayForSourceRoute) {
-      SchedulerBinding.instance!
+      _ambiguate(SchedulerBinding.instance)!
           .addPostFrameCallback(takeMeasurementsInSourceRoute);
     } else {
       takeMeasurementsInSourceRoute();
@@ -901,3 +901,11 @@
     return _flipped;
   }
 }
+
+/// This allows a value of type T or T? to be treated as a value of type T?.
+///
+/// We use this so that APIs that have become non-nullable can still be used
+/// with `!` and `?` on the stable branch.
+// TODO(ianh): Remove this once the relevant APIs have shipped to stable.
+// See https://github.com/flutter/flutter/issues/64830
+T? _ambiguate<T>(T? value) => value;
diff --git a/packages/flutter_image/test/network_test.dart b/packages/flutter_image/test/network_test.dart
index 9f1ffb6..10a5727 100644
--- a/packages/flutter_image/test/network_test.dart
+++ b/packages/flutter_image/test/network_test.dart
@@ -137,26 +137,42 @@
 }
 
 void assertThatImageLoadingFails(
-    NetworkImageWithRetry subject, List<FlutterErrorDetails> errorLog) {
-  subject
-      .load(subject, PaintingBinding.instance!.instantiateImageCodec)
-      .addListener(ImageStreamListener(
-        (ImageInfo image, bool synchronousCall) {},
-        onError: expectAsync2((Object error, StackTrace? _) {
-          expect(errorLog.single.exception, isInstanceOf<FetchFailure>());
-          expect(error, isInstanceOf<FetchFailure>());
-          expect(error, equals(errorLog.single.exception));
-        }),
-      ));
+  NetworkImageWithRetry subject,
+  List<FlutterErrorDetails> errorLog,
+) {
+  final ImageStreamCompleter completer = subject.load(
+    subject,
+    _ambiguate(PaintingBinding.instance)!.instantiateImageCodec,
+  );
+  completer.addListener(ImageStreamListener(
+    (ImageInfo image, bool synchronousCall) {},
+    onError: expectAsync2((Object error, StackTrace? _) {
+      expect(errorLog.single.exception, isInstanceOf<FetchFailure>());
+      expect(error, isInstanceOf<FetchFailure>());
+      expect(error, equals(errorLog.single.exception));
+    }),
+  ));
 }
 
-void assertThatImageLoadingSucceeds(NetworkImageWithRetry subject) {
-  subject
-      .load(subject, PaintingBinding.instance!.instantiateImageCodec)
-      .addListener(
-    ImageStreamListener(expectAsync2((ImageInfo image, bool synchronousCall) {
+void assertThatImageLoadingSucceeds(
+  NetworkImageWithRetry subject,
+) {
+  final ImageStreamCompleter completer = subject.load(
+    subject,
+    _ambiguate(PaintingBinding.instance)!.instantiateImageCodec,
+  );
+  completer.addListener(ImageStreamListener(
+    expectAsync2((ImageInfo image, bool synchronousCall) {
       expect(image.image.height, 1);
       expect(image.image.width, 1);
-    })),
-  );
+    }),
+  ));
 }
+
+/// This allows a value of type T or T? to be treated as a value of type T?.
+///
+/// We use this so that APIs that have become non-nullable can still be used
+/// with `!` and `?` on the stable branch.
+// TODO(ianh): Remove this once the relevant APIs have shipped to stable.
+// See https://github.com/flutter/flutter/issues/64830
+T? _ambiguate<T>(T? value) => value;
diff --git a/packages/flutter_markdown/test/utils.dart b/packages/flutter_markdown/test/utils.dart
index 497d257..dcf5288 100644
--- a/packages/flutter_markdown/test/utils.dart
+++ b/packages/flutter_markdown/test/utils.dart
@@ -154,9 +154,13 @@
 }
 
 String dumpRenderView() {
-  return WidgetsBinding.instance!.renderViewElement!.toStringDeep().replaceAll(
-      RegExp(r'SliverChildListDelegate#\d+', multiLine: true),
-      'SliverChildListDelegate');
+  return _ambiguate(WidgetsBinding.instance)!
+      .renderViewElement!
+      .toStringDeep()
+      .replaceAll(
+        RegExp(r'SliverChildListDelegate#\d+', multiLine: true),
+        'SliverChildListDelegate',
+      );
 }
 
 /// Wraps a widget with a left-to-right [Directionality] for tests.
@@ -197,3 +201,11 @@
     }
   }
 }
+
+/// This allows a value of type T or T? to be treated as a value of type T?.
+///
+/// We use this so that APIs that have become non-nullable can still be used
+/// with `!` and `?` on the stable branch.
+// TODO(ianh): Remove this once the relevant APIs have shipped to stable.
+// See https://github.com/flutter/flutter/issues/64830
+T? _ambiguate<T>(T? value) => value;
diff --git a/packages/rfw/example/wasm/lib/main.dart b/packages/rfw/example/wasm/lib/main.dart
index c91b4d0..007f1f2 100644
--- a/packages/rfw/example/wasm/lib/main.dart
+++ b/packages/rfw/example/wasm/lib/main.dart
@@ -38,7 +38,7 @@
   @override
   void initState() {
     super.initState();
-    RendererBinding.instance!.deferFirstFrame();
+    _ambiguate(RendererBinding.instance)!.deferFirstFrame();
     _runtime.update(const LibraryName(<String>['core', 'widgets']), createCoreWidgets());
     _loadLogic();
   }
@@ -62,7 +62,7 @@
     _logic = WasmModule(await logicFile.readAsBytes()).builder().build();
     _dataFetcher = _logic.lookupFunction('value');
     _updateData();
-    setState(() { RendererBinding.instance!.allowFirstFrame(); });
+    setState(() { _ambiguate(RendererBinding.instance)!.allowFirstFrame(); });
   }
 
   void _updateData() {
@@ -78,7 +78,7 @@
 
   @override
   Widget build(BuildContext context) {
-    if (!RendererBinding.instance!.sendFramesToEngine)
+    if (!_ambiguate(RendererBinding.instance)!.sendFramesToEngine)
       return const SizedBox.shrink();
     return RemoteWidget(
       runtime: _runtime,
@@ -92,3 +92,11 @@
     );
   }
 }
+
+/// This allows a value of type T or T? to be treated as a value of type T?.
+///
+/// We use this so that APIs that have become non-nullable can still be used
+/// with `!` and `?` on the stable branch.
+// TODO(ianh): Remove this once the relevant APIs have shipped to stable.
+// See https://github.com/flutter/flutter/issues/64830
+T? _ambiguate<T>(T? value) => value;