From b09c70a9137cde3c5bff3fc41ad80f7047e7683e Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Thu, 2 Nov 2023 11:21:55 -0700 Subject: [PATCH] Fix mounted checks (#137778) Fixes in preparation for https://dart-review.googlesource.com/c/sdk/+/330561. The change referenced above tightens the `use_build_context_synchronously` to ensure that `mounted` is checked on the appropriate `BuildContext` or `State`. This change fixes up the flutter/flutter in preparation of this new enforcement. --- .../android_views/lib/motion_events_page.dart | 6 +++--- dev/integration_tests/flutter_gallery/lib/gallery/demo.dart | 2 +- .../hybrid_android_views/lib/motion_events_page.dart | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dev/integration_tests/android_views/lib/motion_events_page.dart b/dev/integration_tests/android_views/lib/motion_events_page.dart index 740aa6041f0..b146f57bb6a 100644 --- a/dev/integration_tests/android_views/lib/motion_events_page.dart +++ b/dev/integration_tests/android_views/lib/motion_events_page.dart @@ -175,7 +175,7 @@ class MotionEventsBodyState extends State { Future saveRecordedEvents(ByteData data, BuildContext context) async { if (await channel.invokeMethod('getStoragePermission') ?? false) { - if (mounted) { + if (context.mounted) { showMessage(context, 'External storage permissions are required to save events'); } return; @@ -185,12 +185,12 @@ class MotionEventsBodyState extends State { // This test only runs on Android so we can assume path separator is '/'. final File file = File('${outDir?.path}/$kEventsFileName'); await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true); - if (!mounted) { + if (!context.mounted) { return; } showMessage(context, 'Saved original events to ${file.path}'); } catch (e) { - if (!mounted) { + if (!context.mounted) { return; } showMessage(context, 'Failed saving $e'); diff --git a/dev/integration_tests/flutter_gallery/lib/gallery/demo.dart b/dev/integration_tests/flutter_gallery/lib/gallery/demo.dart index 30acad6b3d1..c064b837ab8 100644 --- a/dev/integration_tests/flutter_gallery/lib/gallery/demo.dart +++ b/dev/integration_tests/flutter_gallery/lib/gallery/demo.dart @@ -80,7 +80,7 @@ class _TabbedComponentDemoScaffoldState extends State( context: context, builder: (BuildContext context) { diff --git a/dev/integration_tests/hybrid_android_views/lib/motion_events_page.dart b/dev/integration_tests/hybrid_android_views/lib/motion_events_page.dart index ad50892a34a..7062d6f6daa 100644 --- a/dev/integration_tests/hybrid_android_views/lib/motion_events_page.dart +++ b/dev/integration_tests/hybrid_android_views/lib/motion_events_page.dart @@ -157,7 +157,7 @@ class MotionEventsBodyState extends State { Future saveRecordedEvents(ByteData data, BuildContext context) async { if (await channel.invokeMethod('getStoragePermission') != true) { - if (mounted) { + if (context.mounted) { showMessage(context, 'External storage permissions are required to save events'); } return; @@ -167,12 +167,12 @@ class MotionEventsBodyState extends State { // This test only runs on Android so we can assume path separator is '/'. final File file = File('${outDir.path}/$kEventsFileName'); await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true); - if (!mounted) { + if (!context.mounted) { return; } showMessage(context, 'Saved original events to ${file.path}'); } catch (e) { - if (!mounted) { + if (!context.mounted) { return; } showMessage(context, 'Failed saving $e');