Skip to content

Commit b09c70a

Browse files
authored
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.
1 parent f15f231 commit b09c70a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

dev/integration_tests/android_views/lib/motion_events_page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
175175

176176
Future<void> saveRecordedEvents(ByteData data, BuildContext context) async {
177177
if (await channel.invokeMethod<bool>('getStoragePermission') ?? false) {
178-
if (mounted) {
178+
if (context.mounted) {
179179
showMessage(context, 'External storage permissions are required to save events');
180180
}
181181
return;
@@ -185,12 +185,12 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
185185
// This test only runs on Android so we can assume path separator is '/'.
186186
final File file = File('${outDir?.path}/$kEventsFileName');
187187
await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true);
188-
if (!mounted) {
188+
if (!context.mounted) {
189189
return;
190190
}
191191
showMessage(context, 'Saved original events to ${file.path}');
192192
} catch (e) {
193-
if (!mounted) {
193+
if (!context.mounted) {
194194
return;
195195
}
196196
showMessage(context, 'Failed saving $e');

dev/integration_tests/flutter_gallery/lib/gallery/demo.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _TabbedComponentDemoScaffoldState extends State<TabbedComponentDemoScaffol
8080
final Uri uri = Uri.parse(url);
8181
if (await canLaunchUrl(uri)) {
8282
await launchUrl(uri);
83-
} else if (mounted) {
83+
} else if (context.mounted) {
8484
showDialog<void>(
8585
context: context,
8686
builder: (BuildContext context) {

dev/integration_tests/hybrid_android_views/lib/motion_events_page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
157157

158158
Future<void> saveRecordedEvents(ByteData data, BuildContext context) async {
159159
if (await channel.invokeMethod<bool>('getStoragePermission') != true) {
160-
if (mounted) {
160+
if (context.mounted) {
161161
showMessage(context, 'External storage permissions are required to save events');
162162
}
163163
return;
@@ -167,12 +167,12 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
167167
// This test only runs on Android so we can assume path separator is '/'.
168168
final File file = File('${outDir.path}/$kEventsFileName');
169169
await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true);
170-
if (!mounted) {
170+
if (!context.mounted) {
171171
return;
172172
}
173173
showMessage(context, 'Saved original events to ${file.path}');
174174
} catch (e) {
175-
if (!mounted) {
175+
if (!context.mounted) {
176176
return;
177177
}
178178
showMessage(context, 'Failed saving $e');

0 commit comments

Comments
 (0)